Spaces:
Sleeping
Sleeping
wip
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ from __future__ import annotations
|
|
| 5 |
import os
|
| 6 |
import urllib.parse
|
| 7 |
import numpy as np
|
|
|
|
| 8 |
from typing import Optional
|
| 9 |
|
| 10 |
import gradio as gr
|
|
@@ -14,6 +15,10 @@ from fastapi.staticfiles import StaticFiles
|
|
| 14 |
from engine import SceneState, POSITION_OFFSETS, Choice, InputRequest
|
| 15 |
from story import build_sample_story
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
def passthrough_stream(frame):
|
| 19 |
"""Return the incoming frame untouched so the user sees their feed."""
|
|
@@ -1431,16 +1436,35 @@ def main() -> None:
|
|
| 1431 |
script_dir = os.path.dirname(os.path.abspath(__file__))
|
| 1432 |
assets_dir = os.path.join(script_dir, "assets")
|
| 1433 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1434 |
# Build Gradio app
|
|
|
|
| 1435 |
demo = build_app()
|
| 1436 |
|
| 1437 |
# Queue must be enabled to access the FastAPI app
|
|
|
|
| 1438 |
demo.queue()
|
| 1439 |
|
| 1440 |
# Mount static files on Gradio's internal FastAPI app
|
|
|
|
| 1441 |
demo.app.mount("/assets", StaticFiles(directory=assets_dir, html=False), name="assets")
|
|
|
|
| 1442 |
|
| 1443 |
# Launch without SSR to avoid MIME type issues
|
|
|
|
| 1444 |
demo.launch(
|
| 1445 |
server_name="0.0.0.0",
|
| 1446 |
server_port=7860,
|
|
|
|
| 5 |
import os
|
| 6 |
import urllib.parse
|
| 7 |
import numpy as np
|
| 8 |
+
import logging
|
| 9 |
from typing import Optional
|
| 10 |
|
| 11 |
import gradio as gr
|
|
|
|
| 15 |
from engine import SceneState, POSITION_OFFSETS, Choice, InputRequest
|
| 16 |
from story import build_sample_story
|
| 17 |
|
| 18 |
+
# Setup logging
|
| 19 |
+
logging.basicConfig(level=logging.INFO)
|
| 20 |
+
logger = logging.getLogger(__name__)
|
| 21 |
+
|
| 22 |
|
| 23 |
def passthrough_stream(frame):
|
| 24 |
"""Return the incoming frame untouched so the user sees their feed."""
|
|
|
|
| 1436 |
script_dir = os.path.dirname(os.path.abspath(__file__))
|
| 1437 |
assets_dir = os.path.join(script_dir, "assets")
|
| 1438 |
|
| 1439 |
+
logger.info(f"=== Visual Novel App Startup ===")
|
| 1440 |
+
logger.info(f"Script directory: {script_dir}")
|
| 1441 |
+
logger.info(f"Assets directory: {assets_dir}")
|
| 1442 |
+
logger.info(f"Assets directory exists: {os.path.exists(assets_dir)}")
|
| 1443 |
+
|
| 1444 |
+
# Check if asset subdirectories exist
|
| 1445 |
+
for subdir in ["backgrounds", "sprites", "audio"]:
|
| 1446 |
+
subdir_path = os.path.join(assets_dir, subdir)
|
| 1447 |
+
exists = os.path.exists(subdir_path)
|
| 1448 |
+
logger.info(f" {subdir}/ exists: {exists}")
|
| 1449 |
+
if exists:
|
| 1450 |
+
files = os.listdir(subdir_path)
|
| 1451 |
+
logger.info(f" {subdir}/ files: {files[:5]}") # Show first 5 files
|
| 1452 |
+
|
| 1453 |
# Build Gradio app
|
| 1454 |
+
logger.info("Building Gradio app...")
|
| 1455 |
demo = build_app()
|
| 1456 |
|
| 1457 |
# Queue must be enabled to access the FastAPI app
|
| 1458 |
+
logger.info("Enabling queue...")
|
| 1459 |
demo.queue()
|
| 1460 |
|
| 1461 |
# Mount static files on Gradio's internal FastAPI app
|
| 1462 |
+
logger.info(f"Mounting /assets -> {assets_dir}")
|
| 1463 |
demo.app.mount("/assets", StaticFiles(directory=assets_dir, html=False), name="assets")
|
| 1464 |
+
logger.info("Static files mounted successfully")
|
| 1465 |
|
| 1466 |
# Launch without SSR to avoid MIME type issues
|
| 1467 |
+
logger.info("Launching app...")
|
| 1468 |
demo.launch(
|
| 1469 |
server_name="0.0.0.0",
|
| 1470 |
server_port=7860,
|
engine.py
CHANGED
|
@@ -4,9 +4,12 @@ from __future__ import annotations
|
|
| 4 |
|
| 5 |
import copy
|
| 6 |
import os
|
|
|
|
| 7 |
from dataclasses import dataclass, field
|
| 8 |
from typing import Dict, List, Optional
|
| 9 |
|
|
|
|
|
|
|
| 10 |
DEFAULT_BACKGROUND = "https://images.unsplash.com/photo-1506744038136-46273834b3fb?auto=format&fit=crop&w=1200&q=80"
|
| 11 |
POSITION_OFFSETS = {
|
| 12 |
"left": "20%",
|
|
@@ -18,17 +21,29 @@ POSITION_OFFSETS = {
|
|
| 18 |
# Asset helper functions
|
| 19 |
def background_asset(filename: str) -> str:
|
| 20 |
"""Get the URL for a background image."""
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
def sprite_asset(filename: str) -> str:
|
| 25 |
"""Get the URL for a sprite image."""
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
def audio_asset(filename: str) -> str:
|
| 30 |
"""Get the URL for an audio file."""
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
|
| 34 |
def create_sprite_data_url(bg_color: str = "#fef3c7", border_color: str = "#ea580c") -> str:
|
|
|
|
| 4 |
|
| 5 |
import copy
|
| 6 |
import os
|
| 7 |
+
import logging
|
| 8 |
from dataclasses import dataclass, field
|
| 9 |
from typing import Dict, List, Optional
|
| 10 |
|
| 11 |
+
logger = logging.getLogger(__name__)
|
| 12 |
+
|
| 13 |
DEFAULT_BACKGROUND = "https://images.unsplash.com/photo-1506744038136-46273834b3fb?auto=format&fit=crop&w=1200&q=80"
|
| 14 |
POSITION_OFFSETS = {
|
| 15 |
"left": "20%",
|
|
|
|
| 21 |
# Asset helper functions
|
| 22 |
def background_asset(filename: str) -> str:
|
| 23 |
"""Get the URL for a background image."""
|
| 24 |
+
url = f"/assets/backgrounds/{filename}"
|
| 25 |
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
| 26 |
+
filepath = os.path.join(script_dir, "assets", "backgrounds", filename)
|
| 27 |
+
logger.info(f"background_asset({filename}) -> {url} (exists: {os.path.exists(filepath)})")
|
| 28 |
+
return url
|
| 29 |
|
| 30 |
|
| 31 |
def sprite_asset(filename: str) -> str:
|
| 32 |
"""Get the URL for a sprite image."""
|
| 33 |
+
url = f"/assets/sprites/{filename}"
|
| 34 |
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
| 35 |
+
filepath = os.path.join(script_dir, "assets", "sprites", filename)
|
| 36 |
+
logger.info(f"sprite_asset({filename}) -> {url} (exists: {os.path.exists(filepath)})")
|
| 37 |
+
return url
|
| 38 |
|
| 39 |
|
| 40 |
def audio_asset(filename: str) -> str:
|
| 41 |
"""Get the URL for an audio file."""
|
| 42 |
+
url = f"/assets/audio/{filename}"
|
| 43 |
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
| 44 |
+
filepath = os.path.join(script_dir, "assets", "audio", filename)
|
| 45 |
+
logger.info(f"audio_asset({filename}) -> {url} (exists: {os.path.exists(filepath)})")
|
| 46 |
+
return url
|
| 47 |
|
| 48 |
|
| 49 |
def create_sprite_data_url(bg_color: str = "#fef3c7", border_color: str = "#ea580c") -> str:
|