rabiyulfahim commited on
Commit
511a6d9
·
verified ·
1 Parent(s): 287f932

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -0
app.py CHANGED
@@ -4,6 +4,8 @@ import torch
4
  import os
5
  from pydantic import BaseModel
6
  from fastapi.middleware.cors import CORSMiddleware
 
 
7
 
8
 
9
  # ✅ Force Hugging Face cache to /tmp (writable in Spaces)
@@ -46,6 +48,15 @@ def ask(question: str, max_new_tokens: int = 50):
46
  return {"question": question, "answer": answer}
47
 
48
 
 
 
 
 
 
 
 
 
 
49
 
50
  # Health check endpoint
51
  @app.get("/health")
 
4
  import os
5
  from pydantic import BaseModel
6
  from fastapi.middleware.cors import CORSMiddleware
7
+ from fastapi.responses import HTMLResponse
8
+ from fastapi.staticfiles import StaticFiles
9
 
10
 
11
  # ✅ Force Hugging Face cache to /tmp (writable in Spaces)
 
48
  return {"question": question, "answer": answer}
49
 
50
 
51
+ # Mount static folder
52
+ app.mount("/static", StaticFiles(directory="static"), name="static")
53
+
54
+ @app.get("/ui", response_class=HTMLResponse)
55
+ def serve_ui():
56
+ html_path = os.path.join("static", "index.html")
57
+ with open(html_path, "r", encoding="utf-8") as f:
58
+ return HTMLResponse(f.read())
59
+
60
 
61
  # Health check endpoint
62
  @app.get("/health")