Spaces:
Sleeping
Sleeping
wip
Browse files
app.py
CHANGED
|
@@ -721,14 +721,16 @@ async (currentDevices) => {
|
|
| 721 |
"""
|
| 722 |
|
| 723 |
def load_dxl_script_js() -> str:
|
| 724 |
-
"""Load the DXL script from static files."""
|
| 725 |
import time
|
|
|
|
|
|
|
| 726 |
timestamp = int(time.time())
|
| 727 |
return f"""
|
| 728 |
() => {{
|
| 729 |
const script = document.createElement('script');
|
| 730 |
script.type = 'module';
|
| 731 |
-
script.src = '/
|
| 732 |
script.onerror = () => console.error("[DXL] Failed to load motor control script");
|
| 733 |
script.onload = () => console.log("[DXL] Script loaded successfully");
|
| 734 |
document.head.appendChild(script);
|
|
@@ -971,11 +973,6 @@ async (pose_data) => {
|
|
| 971 |
|
| 972 |
|
| 973 |
def build_app() -> gr.Blocks:
|
| 974 |
-
# Get absolute paths for static directories
|
| 975 |
-
script_dir = os.path.dirname(os.path.abspath(__file__))
|
| 976 |
-
assets_dir = os.path.join(script_dir, "assets")
|
| 977 |
-
web_dir = os.path.join(script_dir, "web")
|
| 978 |
-
|
| 979 |
with gr.Blocks(title="Gradio Visual Novel") as demo:
|
| 980 |
gr.HTML(f"<style>{CUSTOM_CSS}</style>", elem_id="vn-styles")
|
| 981 |
story_state = gr.State()
|
|
@@ -1438,29 +1435,21 @@ def build_app() -> gr.Blocks:
|
|
| 1438 |
|
| 1439 |
|
| 1440 |
def main() -> None:
|
| 1441 |
-
"""Launch the Visual Novel Gradio app
|
| 1442 |
-
# Create FastAPI app
|
| 1443 |
-
fastapi_app = FastAPI()
|
| 1444 |
-
|
| 1445 |
# Get absolute paths for static directories
|
| 1446 |
script_dir = os.path.dirname(os.path.abspath(__file__))
|
| 1447 |
assets_dir = os.path.join(script_dir, "assets")
|
| 1448 |
web_dir = os.path.join(script_dir, "web")
|
| 1449 |
|
| 1450 |
-
#
|
| 1451 |
-
|
| 1452 |
-
fastapi_app.mount("/web", StaticFilesWithMimeTypes(directory=web_dir, html=False), name="web")
|
| 1453 |
-
|
| 1454 |
-
# Build and mount Gradio app
|
| 1455 |
-
gradio_app = build_app()
|
| 1456 |
-
fastapi_app = gr.mount_gradio_app(fastapi_app, gradio_app, path="/")
|
| 1457 |
|
| 1458 |
-
# Launch
|
| 1459 |
-
|
| 1460 |
-
|
| 1461 |
-
|
| 1462 |
-
|
| 1463 |
-
|
| 1464 |
)
|
| 1465 |
|
| 1466 |
|
|
|
|
| 721 |
"""
|
| 722 |
|
| 723 |
def load_dxl_script_js() -> str:
|
| 724 |
+
"""Load the DXL script from static files via Gradio file serving."""
|
| 725 |
import time
|
| 726 |
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
| 727 |
+
js_path = os.path.join(script_dir, "web", "dxl_webserial.js")
|
| 728 |
timestamp = int(time.time())
|
| 729 |
return f"""
|
| 730 |
() => {{
|
| 731 |
const script = document.createElement('script');
|
| 732 |
script.type = 'module';
|
| 733 |
+
script.src = '/file={js_path}?v={timestamp}';
|
| 734 |
script.onerror = () => console.error("[DXL] Failed to load motor control script");
|
| 735 |
script.onload = () => console.log("[DXL] Script loaded successfully");
|
| 736 |
document.head.appendChild(script);
|
|
|
|
| 973 |
|
| 974 |
|
| 975 |
def build_app() -> gr.Blocks:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 976 |
with gr.Blocks(title="Gradio Visual Novel") as demo:
|
| 977 |
gr.HTML(f"<style>{CUSTOM_CSS}</style>", elem_id="vn-styles")
|
| 978 |
story_state = gr.State()
|
|
|
|
| 1435 |
|
| 1436 |
|
| 1437 |
def main() -> None:
|
| 1438 |
+
"""Launch the Visual Novel Gradio app."""
|
|
|
|
|
|
|
|
|
|
| 1439 |
# Get absolute paths for static directories
|
| 1440 |
script_dir = os.path.dirname(os.path.abspath(__file__))
|
| 1441 |
assets_dir = os.path.join(script_dir, "assets")
|
| 1442 |
web_dir = os.path.join(script_dir, "web")
|
| 1443 |
|
| 1444 |
+
# Build Gradio app
|
| 1445 |
+
demo = build_app()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1446 |
|
| 1447 |
+
# Launch without SSR to avoid MIME type issues
|
| 1448 |
+
demo.launch(
|
| 1449 |
+
server_name="0.0.0.0",
|
| 1450 |
+
server_port=7860,
|
| 1451 |
+
ssr_mode=False, # Disable SSR which causes MIME type issues on HF Spaces
|
| 1452 |
+
allowed_paths=[assets_dir, web_dir],
|
| 1453 |
)
|
| 1454 |
|
| 1455 |
|
engine.py
CHANGED
|
@@ -17,18 +17,24 @@ POSITION_OFFSETS = {
|
|
| 17 |
|
| 18 |
# Asset helper functions
|
| 19 |
def background_asset(filename: str) -> str:
|
| 20 |
-
"""Get the URL
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
def sprite_asset(filename: str) -> str:
|
| 25 |
-
"""Get the URL
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
def audio_asset(filename: str) -> str:
|
| 30 |
-
"""Get the URL
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
|
| 34 |
def create_sprite_data_url(bg_color: str = "#fef3c7", border_color: str = "#ea580c") -> str:
|
|
|
|
| 17 |
|
| 18 |
# Asset helper functions
|
| 19 |
def background_asset(filename: str) -> str:
|
| 20 |
+
"""Get the Gradio file URL for a background image."""
|
| 21 |
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
| 22 |
+
filepath = os.path.join(script_dir, "assets", "backgrounds", filename)
|
| 23 |
+
return f"/file={filepath}"
|
| 24 |
|
| 25 |
|
| 26 |
def sprite_asset(filename: str) -> str:
|
| 27 |
+
"""Get the Gradio file URL for a sprite image."""
|
| 28 |
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
| 29 |
+
filepath = os.path.join(script_dir, "assets", "sprites", filename)
|
| 30 |
+
return f"/file={filepath}"
|
| 31 |
|
| 32 |
|
| 33 |
def audio_asset(filename: str) -> str:
|
| 34 |
+
"""Get the Gradio file URL for an audio file."""
|
| 35 |
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
| 36 |
+
filepath = os.path.join(script_dir, "assets", "audio", filename)
|
| 37 |
+
return f"/file={filepath}"
|
| 38 |
|
| 39 |
|
| 40 |
def create_sprite_data_url(bg_color: str = "#fef3c7", border_color: str = "#ea580c") -> str:
|