Spaces:
Sleeping
Sleeping
Commit
·
ecf3a0b
1
Parent(s):
320eff2
- app.py +15 -19
- functions.py +0 -3
app.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
import io
|
|
|
|
|
2 |
from functions import *
|
3 |
from PyPDF2 import PdfReader
|
4 |
import pandas as pd
|
@@ -8,7 +10,6 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
8 |
from langchain_community.document_loaders import UnstructuredURLLoader
|
9 |
from src.api.speech_api import speech_translator_router
|
10 |
from functions import client as supabase
|
11 |
-
from fastapi.exception_handlers import HTTPException
|
12 |
|
13 |
app = FastAPI(title="ConversAI", root_path="/api/v1")
|
14 |
|
@@ -20,24 +21,24 @@ app.add_middleware(
|
|
20 |
allow_headers=["*"],
|
21 |
)
|
22 |
|
|
|
23 |
app.include_router(speech_translator_router, prefix="/speech")
|
24 |
|
25 |
|
26 |
@app.post("/signup")
|
27 |
async def sign_up(email, password):
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
37 |
|
38 |
-
|
39 |
-
except Exception as e:
|
40 |
-
raise HTTPException(status_code=400, detail="Sign-up failed")
|
41 |
|
42 |
|
43 |
@app.post("/session-check")
|
@@ -46,7 +47,6 @@ async def check_session():
|
|
46 |
|
47 |
return res
|
48 |
|
49 |
-
|
50 |
@app.post("/login")
|
51 |
async def sign_in(email, password):
|
52 |
try:
|
@@ -57,11 +57,6 @@ async def sign_in(email, password):
|
|
57 |
access_token = res.session.access_token
|
58 |
refresh_token = res.session.refresh_token
|
59 |
store_session_check = supabase.table("Stores").select("*").filter("StoreID", "eq", user_id).execute()
|
60 |
-
r_ = createUser(username=user_id)
|
61 |
-
if r_['output'] == 'SUCCESS':
|
62 |
-
pass
|
63 |
-
else:
|
64 |
-
return r_
|
65 |
try:
|
66 |
store_id = store_session_check[1][0]["StoreID"]
|
67 |
except:
|
@@ -110,6 +105,7 @@ async def sign_in(email, password):
|
|
110 |
return message
|
111 |
|
112 |
|
|
|
113 |
@app.post("/set-session-data")
|
114 |
async def set_session_data(access_token, refresh_token):
|
115 |
res = supabase.auth.set_session(access_token, refresh_token)
|
|
|
1 |
import io
|
2 |
+
import os
|
3 |
+
|
4 |
from functions import *
|
5 |
from PyPDF2 import PdfReader
|
6 |
import pandas as pd
|
|
|
10 |
from langchain_community.document_loaders import UnstructuredURLLoader
|
11 |
from src.api.speech_api import speech_translator_router
|
12 |
from functions import client as supabase
|
|
|
13 |
|
14 |
app = FastAPI(title="ConversAI", root_path="/api/v1")
|
15 |
|
|
|
21 |
allow_headers=["*"],
|
22 |
)
|
23 |
|
24 |
+
|
25 |
app.include_router(speech_translator_router, prefix="/speech")
|
26 |
|
27 |
|
28 |
@app.post("/signup")
|
29 |
async def sign_up(email, password):
|
30 |
+
res, _ = supabase.auth.sign_up(
|
31 |
+
{"email": email, "password": password, "role": "user"}
|
32 |
+
)
|
33 |
+
user_id = res[1].id
|
34 |
+
r_ = createUser(username=user_id)
|
35 |
+
response = {
|
36 |
+
"status": "success",
|
37 |
+
"code": 200,
|
38 |
+
"message": "Please check you email address for email verification",
|
39 |
+
}
|
40 |
|
41 |
+
return response
|
|
|
|
|
42 |
|
43 |
|
44 |
@app.post("/session-check")
|
|
|
47 |
|
48 |
return res
|
49 |
|
|
|
50 |
@app.post("/login")
|
51 |
async def sign_in(email, password):
|
52 |
try:
|
|
|
57 |
access_token = res.session.access_token
|
58 |
refresh_token = res.session.refresh_token
|
59 |
store_session_check = supabase.table("Stores").select("*").filter("StoreID", "eq", user_id).execute()
|
|
|
|
|
|
|
|
|
|
|
60 |
try:
|
61 |
store_id = store_session_check[1][0]["StoreID"]
|
62 |
except:
|
|
|
105 |
return message
|
106 |
|
107 |
|
108 |
+
|
109 |
@app.post("/set-session-data")
|
110 |
async def set_session_data(access_token, refresh_token):
|
111 |
res = supabase.auth.set_session(access_token, refresh_token)
|
functions.py
CHANGED
@@ -86,14 +86,11 @@ def createUser(username: str) -> dict:
|
|
86 |
if username not in [userData[x]["user_id"] for x in range(len(userData))]:
|
87 |
client.table("ConversAI_UserInfo").insert({"user_id": username, }).execute()
|
88 |
client.table("ConversAI_UserConfig").insert({"user_id": username}).execute()
|
89 |
-
print("Success")
|
90 |
|
91 |
return {
|
92 |
"output": "SUCCESS"
|
93 |
}
|
94 |
else:
|
95 |
-
print("Failed")
|
96 |
-
|
97 |
return {
|
98 |
"output": "USER ALREADY EXISTS"
|
99 |
}
|
|
|
86 |
if username not in [userData[x]["user_id"] for x in range(len(userData))]:
|
87 |
client.table("ConversAI_UserInfo").insert({"user_id": username, }).execute()
|
88 |
client.table("ConversAI_UserConfig").insert({"user_id": username}).execute()
|
|
|
89 |
|
90 |
return {
|
91 |
"output": "SUCCESS"
|
92 |
}
|
93 |
else:
|
|
|
|
|
94 |
return {
|
95 |
"output": "USER ALREADY EXISTS"
|
96 |
}
|