Spaces:
Running
on
Zero
Running
on
Zero
Remove login
Browse files
app.py
CHANGED
@@ -12,13 +12,9 @@ import gradio as gr
|
|
12 |
from threading import Thread
|
13 |
from dotenv import load_dotenv
|
14 |
|
15 |
-
# Import Supabase functions
|
16 |
-
from db_client import get_user_history, update_user_history, delete_user_history
|
17 |
-
|
18 |
# Add these imports
|
19 |
from datetime import datetime
|
20 |
import pytz
|
21 |
-
from gradio.components import LoginButton
|
22 |
from typing import Optional
|
23 |
from transformers import AutoModelForCausalLM, CodeGenTokenizerFast as Tokenizer
|
24 |
import torch
|
@@ -30,9 +26,6 @@ load_dotenv()
|
|
30 |
# Add TESTING variable
|
31 |
TESTING = False
|
32 |
|
33 |
-
IS_LOGGED_IN = False
|
34 |
-
USER_ID = None
|
35 |
-
|
36 |
# Hugging Face model id
|
37 |
# model_id = "mistral-community/pixtral-12b"
|
38 |
model_id = "blanchon/PixDiet-pixtral-nutrition-v2"
|
@@ -89,7 +82,6 @@ processor.tokenizer.pad_token = processor.tokenizer.eos_token
|
|
89 |
@spaces.GPU
|
90 |
def bot_streaming(chatbot, image_input, max_new_tokens=250):
|
91 |
# Preprocess inputs
|
92 |
-
messages = get_user_history(USER_ID)
|
93 |
images = []
|
94 |
text_input = chatbot[-1][0]
|
95 |
|
@@ -158,11 +150,9 @@ def bot_streaming(chatbot, image_input, max_new_tokens=250):
|
|
158 |
print("New_A:\n", response)
|
159 |
print("BOT_STREAMING_CONV_END")
|
160 |
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
]
|
165 |
-
update_user_history(USER_ID, new_history)
|
166 |
|
167 |
|
168 |
seafoam = Seafoam()
|
@@ -268,7 +258,6 @@ with gr.Blocks(
|
|
268 |
)
|
269 |
with gr.Row():
|
270 |
send_btn = gr.Button("Send", variant="primary", visible=True)
|
271 |
-
login_button = LoginButton(visible=True, value="Login")
|
272 |
clear_btn = gr.Button(
|
273 |
"Delete my history",
|
274 |
variant="stop",
|
@@ -281,35 +270,8 @@ with gr.Blocks(
|
|
281 |
return chatbot, ""
|
282 |
|
283 |
def clear_chat():
|
284 |
-
if USER_ID:
|
285 |
-
delete_user_history(USER_ID)
|
286 |
return [], None, ""
|
287 |
|
288 |
-
def user_logged_in(data, user: Optional[gr.OAuthProfile]):
|
289 |
-
global IS_LOGGED_IN, USER_ID
|
290 |
-
|
291 |
-
print("login")
|
292 |
-
print(data)
|
293 |
-
|
294 |
-
profile = get_profile(user)
|
295 |
-
print(profile)
|
296 |
-
user = profile["username"]
|
297 |
-
print(f"User logged in: {USER_ID}")
|
298 |
-
|
299 |
-
if user is not None:
|
300 |
-
USER_ID = user
|
301 |
-
else:
|
302 |
-
USER_ID = "john doe"
|
303 |
-
|
304 |
-
IS_LOGGED_IN = True
|
305 |
-
|
306 |
-
def get_profile(profile) -> dict:
|
307 |
-
print(dir(profile))
|
308 |
-
return {
|
309 |
-
"username": profile.get("username"),
|
310 |
-
"profile": profile.get("profile"),
|
311 |
-
"name": profile.get("name"),
|
312 |
-
}
|
313 |
|
314 |
send_click_event = send_btn.click(
|
315 |
submit_chat, [chatbot, text_input], [chatbot, text_input]
|
@@ -319,13 +281,6 @@ with gr.Blocks(
|
|
319 |
).then(bot_streaming, [chatbot, image_input], chatbot)
|
320 |
clear_btn.click(clear_chat, outputs=[chatbot, image_input, text_input])
|
321 |
|
322 |
-
# Add login event handler
|
323 |
-
login_button.click(
|
324 |
-
user_logged_in,
|
325 |
-
inputs=[login_button],
|
326 |
-
outputs=[login_button, send_btn, clear_btn],
|
327 |
-
)
|
328 |
-
|
329 |
gr.HTML(footer_html)
|
330 |
|
331 |
if __name__ == "__main__":
|
|
|
12 |
from threading import Thread
|
13 |
from dotenv import load_dotenv
|
14 |
|
|
|
|
|
|
|
15 |
# Add these imports
|
16 |
from datetime import datetime
|
17 |
import pytz
|
|
|
18 |
from typing import Optional
|
19 |
from transformers import AutoModelForCausalLM, CodeGenTokenizerFast as Tokenizer
|
20 |
import torch
|
|
|
26 |
# Add TESTING variable
|
27 |
TESTING = False
|
28 |
|
|
|
|
|
|
|
29 |
# Hugging Face model id
|
30 |
# model_id = "mistral-community/pixtral-12b"
|
31 |
model_id = "blanchon/PixDiet-pixtral-nutrition-v2"
|
|
|
82 |
@spaces.GPU
|
83 |
def bot_streaming(chatbot, image_input, max_new_tokens=250):
|
84 |
# Preprocess inputs
|
|
|
85 |
images = []
|
86 |
text_input = chatbot[-1][0]
|
87 |
|
|
|
150 |
print("New_A:\n", response)
|
151 |
print("BOT_STREAMING_CONV_END")
|
152 |
|
153 |
+
new_history = messages + [
|
154 |
+
{"role": "assistant", "content": [{"type": "text", "text": response}]}
|
155 |
+
]
|
|
|
|
|
156 |
|
157 |
|
158 |
seafoam = Seafoam()
|
|
|
258 |
)
|
259 |
with gr.Row():
|
260 |
send_btn = gr.Button("Send", variant="primary", visible=True)
|
|
|
261 |
clear_btn = gr.Button(
|
262 |
"Delete my history",
|
263 |
variant="stop",
|
|
|
270 |
return chatbot, ""
|
271 |
|
272 |
def clear_chat():
|
|
|
|
|
273 |
return [], None, ""
|
274 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
|
276 |
send_click_event = send_btn.click(
|
277 |
submit_chat, [chatbot, text_input], [chatbot, text_input]
|
|
|
281 |
).then(bot_streaming, [chatbot, image_input], chatbot)
|
282 |
clear_btn.click(clear_chat, outputs=[chatbot, image_input, text_input])
|
283 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
gr.HTML(footer_html)
|
285 |
|
286 |
if __name__ == "__main__":
|