dylanglenister commited on
Commit
bc35722
·
1 Parent(s): daebdfa

Extracting static response

Browse files
Files changed (2) hide show
  1. api/routes/static.py +14 -0
  2. app.py +6 -16
api/routes/static.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import APIRouter, HTTPException
2
+ from fastapi.responses import HTMLResponse
3
+
4
+ router = APIRouter()
5
+
6
+ @router.get("/", response_class=HTMLResponse)
7
+ async def get_medical_chatbot():
8
+ """Serve the medical chatbot UI"""
9
+ try:
10
+ with open("static/index.html", "r", encoding="utf-8") as f:
11
+ html_content = f.read()
12
+ return HTMLResponse(content=html_content)
13
+ except FileNotFoundError:
14
+ raise HTTPException(status_code=404, detail="Medical chatbot UI not found")
app.py CHANGED
@@ -3,9 +3,8 @@
3
 
4
  from contextlib import asynccontextmanager
5
 
6
- from fastapi import FastAPI, HTTPException
7
  from fastapi.middleware.cors import CORSMiddleware
8
- from fastapi.responses import HTMLResponse
9
  from fastapi.staticfiles import StaticFiles
10
 
11
  # Load environment variables from .env file
@@ -18,7 +17,7 @@ except ImportError:
18
  except Exception as e:
19
  print(f"⚠️ Error loading .env file: {e}")
20
 
21
- from api.routes import chat, session, system, user
22
  from core.state import MedicalState
23
  from utils.logger import get_logger
24
 
@@ -99,21 +98,12 @@ app.add_middleware(
99
  allow_headers=["*"],
100
  )
101
 
 
 
 
102
  # Include routers
103
  app.include_router(chat.router)
104
  app.include_router(user.router)
105
  app.include_router(session.router)
106
  app.include_router(system.router)
107
-
108
- # Mount static files
109
- app.mount("/static", StaticFiles(directory="static"), name="static")
110
-
111
- @app.get("/", response_class=HTMLResponse)
112
- async def get_medical_chatbot():
113
- """Serve the medical chatbot UI"""
114
- try:
115
- with open("static/index.html", "r", encoding="utf-8") as f:
116
- html_content = f.read()
117
- return HTMLResponse(content=html_content)
118
- except FileNotFoundError:
119
- raise HTTPException(status_code=404, detail="Medical chatbot UI not found")
 
3
 
4
  from contextlib import asynccontextmanager
5
 
6
+ from fastapi import FastAPI
7
  from fastapi.middleware.cors import CORSMiddleware
 
8
  from fastapi.staticfiles import StaticFiles
9
 
10
  # Load environment variables from .env file
 
17
  except Exception as e:
18
  print(f"⚠️ Error loading .env file: {e}")
19
 
20
+ from api.routes import chat, session, static, system, user
21
  from core.state import MedicalState
22
  from utils.logger import get_logger
23
 
 
98
  allow_headers=["*"],
99
  )
100
 
101
+ # Mount static files
102
+ app.mount("/static", StaticFiles(directory="static"), name="static")
103
+
104
  # Include routers
105
  app.include_router(chat.router)
106
  app.include_router(user.router)
107
  app.include_router(session.router)
108
  app.include_router(system.router)
109
+ app.include_router(static.router)