Spaces:
Runtime error
Runtime error
HarshSanghavi
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,48 +1,48 @@
|
|
1 |
-
from fastapi import FastAPI, Request
|
2 |
-
from fastapi.responses import HTMLResponse
|
3 |
-
from fastapi.templating import Jinja2Templates
|
4 |
-
from chat import chat_conversations
|
5 |
-
from database_functions import create_new_session,save_mood_summary
|
6 |
-
import spacy
|
7 |
-
import os
|
8 |
-
import time
|
9 |
-
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
|
10 |
-
app = FastAPI()
|
11 |
-
|
12 |
-
templates = Jinja2Templates(directory="templates")
|
13 |
-
|
14 |
-
@app.get("/", response_class=HTMLResponse)
|
15 |
-
async def read_root(request: Request):
|
16 |
-
return templates.TemplateResponse("chatwidget.html", {"request": request})
|
17 |
-
|
18 |
-
@app.get("/chat", response_class=HTMLResponse)
|
19 |
-
async def read_root(request: Request):
|
20 |
-
return templates.TemplateResponse("chatwidget.html", {"request": request})
|
21 |
-
|
22 |
-
@app.post("/chatwidget", response_class=HTMLResponse)
|
23 |
-
async def read_root(request: Request):
|
24 |
-
start = time.time_ns()
|
25 |
-
form_data = await request.json()
|
26 |
-
query = form_data.get('query')
|
27 |
-
user_id = form_data.get("user_id")
|
28 |
-
response_text = chat_conversations(query,user_id)
|
29 |
-
print("message is send after : ",time.time()- start)
|
30 |
-
return response_text
|
31 |
-
|
32 |
-
@app.post("/start-session")
|
33 |
-
async def start_session(request: Request):
|
34 |
-
start = time.time_ns()
|
35 |
-
form_data = await request.json()
|
36 |
-
# print("form data",form_data)
|
37 |
-
user_id = form_data.get("user_id")
|
38 |
-
# print("save user id ",user_id)
|
39 |
-
response = create_new_session(user_id)
|
40 |
-
print("session is created after : ",time.time()- start)
|
41 |
-
return response
|
42 |
-
|
43 |
-
@app.post("/mood-summary")
|
44 |
-
async def mood_summary(request:Request):
|
45 |
-
form_data = await request.json()
|
46 |
-
user_id = form_data.get("user_id")
|
47 |
-
save_mood_summary(form_data,user_id)
|
48 |
return "mood saved successfully..."
|
|
|
1 |
+
from fastapi import FastAPI, Request
|
2 |
+
from fastapi.responses import HTMLResponse
|
3 |
+
from fastapi.templating import Jinja2Templates
|
4 |
+
from chat import chat_conversations
|
5 |
+
from database_functions import create_new_session,save_mood_summary
|
6 |
+
import spacy
|
7 |
+
import os
|
8 |
+
import time
|
9 |
+
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
|
10 |
+
app = FastAPI()
|
11 |
+
|
12 |
+
templates = Jinja2Templates(directory="templates")
|
13 |
+
|
14 |
+
@app.get("/", response_class=HTMLResponse)
|
15 |
+
async def read_root(request: Request):
|
16 |
+
return templates.TemplateResponse("chatwidget.html", {"request": request})
|
17 |
+
|
18 |
+
@app.get("/chat", response_class=HTMLResponse)
|
19 |
+
async def read_root(request: Request):
|
20 |
+
return templates.TemplateResponse("chatwidget.html", {"request": request})
|
21 |
+
|
22 |
+
@app.post("/chatwidget", response_class=HTMLResponse)
|
23 |
+
async def read_root(request: Request):
|
24 |
+
start = time.time_ns()
|
25 |
+
form_data = await request.json()
|
26 |
+
query = form_data.get('query')
|
27 |
+
user_id = form_data.get("user_id")
|
28 |
+
response_text = chat_conversations(query,user_id)
|
29 |
+
print("message is send after : ",time.time()- start)
|
30 |
+
return response_text
|
31 |
+
|
32 |
+
@app.post("/start-session")
|
33 |
+
async def start_session(request: Request):
|
34 |
+
start = time.time_ns()
|
35 |
+
form_data = await request.json()
|
36 |
+
# print("form data",form_data)
|
37 |
+
user_id = form_data.get("user_id").lower()
|
38 |
+
# print("save user id ",user_id)
|
39 |
+
response = create_new_session(user_id)
|
40 |
+
print("session is created after : ",time.time()- start)
|
41 |
+
return response
|
42 |
+
|
43 |
+
@app.post("/mood-summary")
|
44 |
+
async def mood_summary(request:Request):
|
45 |
+
form_data = await request.json()
|
46 |
+
user_id = form_data.get("user_id").lower()
|
47 |
+
save_mood_summary(form_data,user_id)
|
48 |
return "mood saved successfully..."
|