blanchon commited on
Commit
ed74fca
·
1 Parent(s): 3c092f1
Files changed (2) hide show
  1. README.md +8 -1
  2. app.py +27 -7
README.md CHANGED
@@ -8,13 +8,20 @@ sdk_version: 5.0.2
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
11
- hf_oauth: true
12
  tags:
13
  - mistral
14
  - pixtral
15
  - nutrition
16
  - diet
17
  - chatbot
 
 
 
 
 
 
 
 
18
  ---
19
 
20
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
 
11
  tags:
12
  - mistral
13
  - pixtral
14
  - nutrition
15
  - diet
16
  - chatbot
17
+ hf_oauth: true
18
+ hf_oauth_expiration_minutes: 480
19
+ # optional, see "Scopes" below. "openid profile" is always included.
20
+ hf_oauth_scopes:
21
+ - read-repos
22
+ - write-repos
23
+ - manage-repos
24
+ - inference-api
25
  ---
26
 
27
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py CHANGED
@@ -16,17 +16,18 @@ from db_client import get_user_history, update_user_history, delete_user_history
16
  # Add these imports
17
  from datetime import datetime
18
  import pytz
 
19
 
20
  load_dotenv()
21
 
22
  # Add TESTING variable
23
- TESTING = False # You can change this to False when not testing
24
 
25
- IS_LOGGED_IN = True
26
- USER_ID = "jeremie.feron@gmail.com"
27
 
28
  # Hugging Face model id
29
- model_id = "blanchon/pixtral-nutrition-2"
30
 
31
  # BitsAndBytesConfig int-4 config
32
  bnb_config = BitsAndBytesConfig(
@@ -179,6 +180,8 @@ latex_delimiters_set = [
179
  # Create the Gradio interface
180
  with gr.Blocks(title="PixDiet", theme=gr.themes.Ocean()) as demo:
181
  gr.HTML(html)
 
 
182
  with gr.Row():
183
  with gr.Column(scale=3):
184
  image_input = gr.Image(label="Upload your meal image", height=350, type="pil")
@@ -196,8 +199,9 @@ with gr.Blocks(title="PixDiet", theme=gr.themes.Ocean()) as demo:
196
  chatbot = gr.Chatbot(label="Chat with PixDiet", layout="panel", height=600, show_copy_button=True, latex_delimiters=latex_delimiters_set)
197
  text_input = gr.Textbox(label="Ask about your meal", placeholder="(Optional) Enter your message here...", lines=1, container=False)
198
  with gr.Row():
199
- send_btn = gr.Button("Send", variant="primary")
200
- clear_btn = gr.Button("Delete my historic", variant="secondary")
 
201
 
202
  def submit_chat(chatbot, text_input):
203
  response = ''
@@ -205,9 +209,22 @@ with gr.Blocks(title="PixDiet", theme=gr.themes.Ocean()) as demo:
205
  return chatbot, ''
206
 
207
  def clear_chat():
208
- delete_user_history(USER_ID)
 
209
  return [], None, ""
210
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  send_click_event = send_btn.click(submit_chat, [chatbot, text_input], [chatbot, text_input]).then(
212
  bot_streaming, [chatbot, image_input], chatbot
213
  )
@@ -216,5 +233,8 @@ with gr.Blocks(title="PixDiet", theme=gr.themes.Ocean()) as demo:
216
  )
217
  clear_btn.click(clear_chat, outputs=[chatbot, image_input, text_input])
218
 
 
 
 
219
  if __name__ == "__main__":
220
  demo.launch(debug=False, share=False, show_api=False)
 
16
  # Add these imports
17
  from datetime import datetime
18
  import pytz
19
+ from gradio.components import LoginButton
20
 
21
  load_dotenv()
22
 
23
  # Add TESTING variable
24
+ TESTING = False
25
 
26
+ IS_LOGGED_IN = False
27
+ USER_ID = None
28
 
29
  # Hugging Face model id
30
+ model_id = "mistral-community/pixtral-12b"
31
 
32
  # BitsAndBytesConfig int-4 config
33
  bnb_config = BitsAndBytesConfig(
 
180
  # Create the Gradio interface
181
  with gr.Blocks(title="PixDiet", theme=gr.themes.Ocean()) as demo:
182
  gr.HTML(html)
183
+
184
+
185
  with gr.Row():
186
  with gr.Column(scale=3):
187
  image_input = gr.Image(label="Upload your meal image", height=350, type="pil")
 
199
  chatbot = gr.Chatbot(label="Chat with PixDiet", layout="panel", height=600, show_copy_button=True, latex_delimiters=latex_delimiters_set)
200
  text_input = gr.Textbox(label="Ask about your meal", placeholder="(Optional) Enter your message here...", lines=1, container=False)
201
  with gr.Row():
202
+ send_btn = gr.Button("Send", variant="primary", visible=False)
203
+ login_button = LoginButton(visible=True)
204
+ clear_btn = gr.Button("Delete my historic", variant="stop", visible=False)
205
 
206
  def submit_chat(chatbot, text_input):
207
  response = ''
 
209
  return chatbot, ''
210
 
211
  def clear_chat():
212
+ if USER_ID:
213
+ delete_user_history(USER_ID)
214
  return [], None, ""
215
 
216
+ def user_logged_in(user):
217
+ global IS_LOGGED_IN, USER_ID
218
+ if user is not None:
219
+ IS_LOGGED_IN = True
220
+ USER_ID = user.email
221
+ print(f"User logged in: {USER_ID}")
222
+ return gr.update(visible=False), gr.update(visible=True), gr.update(visible=True)
223
+ else:
224
+ IS_LOGGED_IN = False
225
+ USER_ID = None
226
+ return gr.update
227
+
228
  send_click_event = send_btn.click(submit_chat, [chatbot, text_input], [chatbot, text_input]).then(
229
  bot_streaming, [chatbot, image_input], chatbot
230
  )
 
233
  )
234
  clear_btn.click(clear_chat, outputs=[chatbot, image_input, text_input])
235
 
236
+ # Add login event handler
237
+ login_button.click(user_logged_in, inputs=[login_button], outputs=[login_button])
238
+
239
  if __name__ == "__main__":
240
  demo.launch(debug=False, share=False, show_api=False)