Spaces:
Sleeping
Sleeping
UPDATE: speed ups
Browse files- app.py +76 -2
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import io
|
2 |
-
import
|
3 |
-
import tempfile
|
4 |
from functions import *
|
5 |
import pandas as pd
|
6 |
from fastapi import FastAPI, File, UploadFile, HTTPException
|
@@ -11,6 +10,7 @@ from functions import client as supabase
|
|
11 |
from urllib.parse import urlparse
|
12 |
import nltk
|
13 |
|
|
|
14 |
nltk.download('punkt_tab')
|
15 |
|
16 |
app = FastAPI(title="ConversAI", root_path="/api/v1")
|
@@ -33,6 +33,7 @@ async def sign_up(email, username, password):
|
|
33 |
)
|
34 |
user_id = res[1].id
|
35 |
r_ = createUser(user_id=user_id, username=username)
|
|
|
36 |
|
37 |
response = {
|
38 |
"status": "success",
|
@@ -49,6 +50,18 @@ async def check_session():
|
|
49 |
|
50 |
return res
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
@app.post("/login")
|
54 |
async def sign_in(email, password):
|
@@ -60,6 +73,66 @@ async def sign_in(email, password):
|
|
60 |
access_token = res.session.access_token
|
61 |
refresh_token = res.session.refresh_token
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
store_session_check = supabase.table("Stores").select("*").filter("StoreID", "eq", user_id).execute()
|
64 |
store_id = None
|
65 |
|
@@ -108,6 +181,7 @@ async def sign_in(email, password):
|
|
108 |
)
|
109 |
|
110 |
|
|
|
111 |
@app.post("/set-session-data")
|
112 |
async def set_session_data(access_token, refresh_token):
|
113 |
res = supabase.auth.set_session(access_token, refresh_token)
|
|
|
1 |
import io
|
2 |
+
from starlette import status
|
|
|
3 |
from functions import *
|
4 |
import pandas as pd
|
5 |
from fastapi import FastAPI, File, UploadFile, HTTPException
|
|
|
10 |
from urllib.parse import urlparse
|
11 |
import nltk
|
12 |
|
13 |
+
|
14 |
nltk.download('punkt_tab')
|
15 |
|
16 |
app = FastAPI(title="ConversAI", root_path="/api/v1")
|
|
|
33 |
)
|
34 |
user_id = res[1].id
|
35 |
r_ = createUser(user_id=user_id, username=username)
|
36 |
+
print(r_)
|
37 |
|
38 |
response = {
|
39 |
"status": "success",
|
|
|
50 |
|
51 |
return res
|
52 |
|
53 |
+
@app.post("/get-user")
|
54 |
+
async def get_user(access_token):
|
55 |
+
res = supabase.auth.get_user(jwt=access_token)
|
56 |
+
return res
|
57 |
+
|
58 |
+
|
59 |
+
@app.post("/referesh-token")
|
60 |
+
async def refresh_token(refresh_token):
|
61 |
+
res = supabase.auth.refresh_token(refresh_token)
|
62 |
+
return res
|
63 |
+
|
64 |
+
|
65 |
|
66 |
@app.post("/login")
|
67 |
async def sign_in(email, password):
|
|
|
73 |
access_token = res.session.access_token
|
74 |
refresh_token = res.session.refresh_token
|
75 |
|
76 |
+
store_session_check = supabase.table("Stores").select("*").filter("StoreID", "eq", user_id).execute()
|
77 |
+
store_id = None
|
78 |
+
if store_session_check and store_session_check.data:
|
79 |
+
store_id = store_session_check.data[0].get("StoreID")
|
80 |
+
|
81 |
+
userData = client.table("ConversAI_UserInfo").select("*").filter("user_id", "eq", user_id).execute().data
|
82 |
+
username = userData[0]["username"]
|
83 |
+
|
84 |
+
if not store_id:
|
85 |
+
response = (
|
86 |
+
supabase.table("Stores").insert(
|
87 |
+
{
|
88 |
+
"AccessToken": access_token,
|
89 |
+
"StoreID": user_id,
|
90 |
+
"RefreshToken": refresh_token,
|
91 |
+
}
|
92 |
+
).execute()
|
93 |
+
)
|
94 |
+
|
95 |
+
message = {
|
96 |
+
"message": "Success",
|
97 |
+
"code": status.HTTP_200_OK,
|
98 |
+
"username": username,
|
99 |
+
"user_id": user_id,
|
100 |
+
"access_token": access_token,
|
101 |
+
"refresh_token": refresh_token,
|
102 |
+
}
|
103 |
+
return message
|
104 |
+
|
105 |
+
elif store_id == user_id:
|
106 |
+
raise HTTPException(
|
107 |
+
status_code=status.HTTP_400_BAD_REQUEST,
|
108 |
+
detail="You are already signed in. Please sign out first to sign in again."
|
109 |
+
)
|
110 |
+
|
111 |
+
else:
|
112 |
+
raise HTTPException(
|
113 |
+
status_code=status.HTTP_400_BAD_REQUEST,
|
114 |
+
detail="Failed to sign in. Please check your credentials."
|
115 |
+
)
|
116 |
+
|
117 |
+
except HTTPException as http_exc:
|
118 |
+
raise http_exc
|
119 |
+
|
120 |
+
except Exception as e:
|
121 |
+
raise HTTPException(
|
122 |
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
123 |
+
detail=f"An unexpected error occurred during sign-in: {str(e)}"
|
124 |
+
)
|
125 |
+
|
126 |
+
|
127 |
+
@app.post('login_with_token')
|
128 |
+
async def login_with_token(token):
|
129 |
+
try:
|
130 |
+
res = supabase.auth.sign_in_with_id_token(token)
|
131 |
+
print(res)
|
132 |
+
user_id = res.user.id
|
133 |
+
access_token = res.session.access_token
|
134 |
+
refresh_token = res.session.refresh_token
|
135 |
+
|
136 |
store_session_check = supabase.table("Stores").select("*").filter("StoreID", "eq", user_id).execute()
|
137 |
store_id = None
|
138 |
|
|
|
181 |
)
|
182 |
|
183 |
|
184 |
+
|
185 |
@app.post("/set-session-data")
|
186 |
async def set_session_data(access_token, refresh_token):
|
187 |
res = supabase.auth.set_session(access_token, refresh_token)
|
requirements.txt
CHANGED
@@ -93,4 +93,5 @@ langsmith
|
|
93 |
pandasai
|
94 |
easyocr
|
95 |
youtube-transcript-api
|
96 |
-
pdf2image
|
|
|
|
93 |
pandasai
|
94 |
easyocr
|
95 |
youtube-transcript-api
|
96 |
+
pdf2image
|
97 |
+
PyPDF2
|