Spaces:
Sleeping
Sleeping
Phillip Holland commited on
Commit ·
9f31444
1
Parent(s): fc472e7
Patch Gradio file schema bug
Browse files- app.py +1 -2
- moonshine/ui.py +12 -0
app.py
CHANGED
|
@@ -5,10 +5,9 @@ from moonshine.ui import build_demo
|
|
| 5 |
|
| 6 |
use_mock = os.getenv("MOONSHINE_USE_MOCK", "1").lower() not in {"0", "false", "no"}
|
| 7 |
port = int(os.getenv("PORT", "7860"))
|
| 8 |
-
is_hf_space = bool(os.getenv("SPACE_ID") or os.getenv("SYSTEM") == "spaces")
|
| 9 |
|
| 10 |
demo = build_demo(use_mock=use_mock)
|
| 11 |
|
| 12 |
|
| 13 |
if __name__ == "__main__":
|
| 14 |
-
demo.launch(server_name="0.0.0.0", server_port=port, show_error=True
|
|
|
|
| 5 |
|
| 6 |
use_mock = os.getenv("MOONSHINE_USE_MOCK", "1").lower() not in {"0", "false", "no"}
|
| 7 |
port = int(os.getenv("PORT", "7860"))
|
|
|
|
| 8 |
|
| 9 |
demo = build_demo(use_mock=use_mock)
|
| 10 |
|
| 11 |
|
| 12 |
if __name__ == "__main__":
|
| 13 |
+
demo.launch(server_name="0.0.0.0", server_port=port, show_error=True)
|
moonshine/ui.py
CHANGED
|
@@ -26,6 +26,18 @@ DEMO_DATA_PATH = ROOT_DIR / "data" / "demo_inputs.jsonl"
|
|
| 26 |
|
| 27 |
def build_demo(use_mock: bool = True):
|
| 28 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
client = MockModelClient() if use_mock else OpenAICompatibleClient()
|
| 31 |
engine = MoonshineEngine(client, MoonshineConfig())
|
|
|
|
| 26 |
|
| 27 |
def build_demo(use_mock: bool = True):
|
| 28 |
import gradio as gr
|
| 29 |
+
import gradio_client.utils as gradio_client_utils
|
| 30 |
+
|
| 31 |
+
if not getattr(gradio_client_utils, "_moonshine_schema_patch", False):
|
| 32 |
+
original = gradio_client_utils._json_schema_to_python_type
|
| 33 |
+
|
| 34 |
+
def _patched_json_schema_to_python_type(schema, defs):
|
| 35 |
+
if isinstance(schema, bool):
|
| 36 |
+
return "Any"
|
| 37 |
+
return original(schema, defs)
|
| 38 |
+
|
| 39 |
+
gradio_client_utils._json_schema_to_python_type = _patched_json_schema_to_python_type
|
| 40 |
+
gradio_client_utils._moonshine_schema_patch = True
|
| 41 |
|
| 42 |
client = MockModelClient() if use_mock else OpenAICompatibleClient()
|
| 43 |
engine = MoonshineEngine(client, MoonshineConfig())
|