Spaces:
Runtime error
Runtime error
| from __future__ import annotations | |
| import os | |
| from gradio import Server | |
| from fastapi.responses import HTMLResponse, FileResponse | |
| import ai | |
| app = Server() | |
| HERE = os.path.dirname(os.path.abspath(__file__)) | |
| try: | |
| from fastapi.staticfiles import StaticFiles | |
| app.mount("/nasset", StaticFiles(directory=os.path.join(HERE, "nasset")), name="nasset") | |
| except Exception as exc: | |
| print(f"[heartwood] could not mount /nasset: {exc}") | |
| def quest(level: int = 1): | |
| return ai.new_quest(level) | |
| def challenge(npc: str = ""): | |
| return ai.challenge_for(npc) | |
| def judge(npc: str = "", mood: str = "", text: str = ""): | |
| return ai.judge(npc, mood, text) | |
| def chat(npc: str = "", text: str = ""): | |
| return {"npc": npc, "line": ai.chat_line(npc, text)} | |
| def mainjs(): | |
| return FileResponse(os.path.join(HERE, "main.js"), media_type="application/javascript") | |
| async def homepage(): | |
| with open(os.path.join(HERE, "index.html"), "r", encoding="utf-8") as f: | |
| return f.read() | |
| if os.environ.get("SS_LLM", "1") == "1": | |
| import threading | |
| import llm | |
| threading.Thread(target=llm.warmup, daemon=True).start() | |
| if __name__ == "__main__": | |
| os.environ.setdefault("GRADIO_SERVER_NAME", "0.0.0.0") | |
| os.environ.setdefault("GRADIO_SERVER_PORT", "7860") | |
| app.launch(show_error=True) | |