Spaces:
Sleeping
Sleeping
MM58-crypto commited on
Commit Β·
9be91cf
1
Parent(s): 1214561
wooo another commit
Browse files
main.py
CHANGED
|
@@ -39,7 +39,7 @@ import requests
|
|
| 39 |
import uuid
|
| 40 |
from dotenv import load_dotenv
|
| 41 |
from datetime import datetime
|
| 42 |
-
|
| 43 |
load_dotenv()
|
| 44 |
|
| 45 |
try:
|
|
@@ -148,6 +148,11 @@ def run_query(message: str, intent: str, session_id: str) -> str:
|
|
| 148 |
app = FastAPI(title="Sebayhi", description="Arabic Grammar Education Tutor")
|
| 149 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
# fastapi middleware here --> cookies / session generation logic
|
| 152 |
@app.middleware("http")
|
| 153 |
async def user_session_management(request: Request, call_next):
|
|
@@ -158,7 +163,7 @@ async def user_session_management(request: Request, call_next):
|
|
| 158 |
|
| 159 |
# this if statement is not running OR session_id is never saved and found on mongodb
|
| 160 |
if session_id:
|
| 161 |
-
retrieved_session = collection.find_one({"
|
| 162 |
print("FOUND SESSION:", session is not None)
|
| 163 |
if retrieved_session:
|
| 164 |
collection.update_one(
|
|
@@ -209,8 +214,8 @@ class ChatRequest(BaseModel):
|
|
| 209 |
# ββ Routes ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 210 |
|
| 211 |
@app.get("/")
|
| 212 |
-
async def serve_ui(
|
| 213 |
-
|
| 214 |
return FileResponse("static/index.html")
|
| 215 |
|
| 216 |
|
|
|
|
| 39 |
import uuid
|
| 40 |
from dotenv import load_dotenv
|
| 41 |
from datetime import datetime
|
| 42 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 43 |
load_dotenv()
|
| 44 |
|
| 45 |
try:
|
|
|
|
| 148 |
app = FastAPI(title="Sebayhi", description="Arabic Grammar Education Tutor")
|
| 149 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 150 |
|
| 151 |
+
app.add_middleware(
|
| 152 |
+
allow_credentials=True,
|
| 153 |
+
allow_methods=["*"],
|
| 154 |
+
allow_headers=["*"]
|
| 155 |
+
)
|
| 156 |
# fastapi middleware here --> cookies / session generation logic
|
| 157 |
@app.middleware("http")
|
| 158 |
async def user_session_management(request: Request, call_next):
|
|
|
|
| 163 |
|
| 164 |
# this if statement is not running OR session_id is never saved and found on mongodb
|
| 165 |
if session_id:
|
| 166 |
+
retrieved_session = collection.find_one({"_id": session_id})
|
| 167 |
print("FOUND SESSION:", session is not None)
|
| 168 |
if retrieved_session:
|
| 169 |
collection.update_one(
|
|
|
|
| 214 |
# ββ Routes ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 215 |
|
| 216 |
@app.get("/")
|
| 217 |
+
async def serve_ui():
|
| 218 |
+
|
| 219 |
return FileResponse("static/index.html")
|
| 220 |
|
| 221 |
|