aaronmat1905 commited on
Commit
55f9440
1 Parent(s): 41bf181
Files changed (1) hide show
  1. app.py +15 -54
app.py CHANGED
@@ -32,65 +32,26 @@ You will ask the customer a single question at a time, which is relevant, and yo
32
  model_path = "gemini-1.5-flash"
33
  FoodSafetyAssistant = genai.GenerativeModel(model_path, system_instruction=system_instruction)
34
 
35
- # Define the function to handle the chat
36
- def respond(usertxt, chat_history):
37
- # Initialize chat with the previous history
38
- chat = FoodSafetyAssistant.start_chat(history=chat_history)
39
-
40
  # Get response from the assistant
41
- response = chat.send_message(usertxt)
42
-
43
- # Append both user input and response to the chat history
44
- chat_history.append({"role": "user", "content": usertxt})
45
- chat_history.append({"role": "assistant", "content": response.text})
46
-
47
- return response.text, chat_history # Return both the response and the updated chat history
48
 
49
  # Gradio interface
50
- def gradio_chat(usertxt, chat_history):
51
- response, updated_history = respond(usertxt, chat_history)
52
- return response, updated_history # Return the response and updated history
53
-
54
- html_content = """
55
- <div style="background-color:#f9f9f9; padding:20px; border-radius:10px;">
56
- <h1 style="color:#34495e;">Food Safety Assistant</h1>
57
- <h3 style="color:#2c3e50;">Your AI-Powered Assistant for Food Safety</h3>
58
- <p style="color:#7f8c8d;">
59
- Our platform allows consumers to report potential food safety violations, validate reports through AI, and notify local authorities. This proactive approach fosters community involvement in ensuring food integrity.
60
- </p>
61
- <h4 style="color:#e74c3c; text-align:center;">Core Functionalities</h4>
62
- <div style="display:flex; justify-content: space-around; align-items:center; margin-top:20px;">
63
- <div style="border: 2px solid #3498db; border-radius: 15px; padding: 20px; width: 150px; text-align: center;">
64
- <h4 style="color:#2980b9;">Report Issues</h4>
65
- <p style="color:#7f8c8d; font-size: 12px;">Submit details like the restaurant name and the issue, anonymously.</p>
66
- </div>
67
- <div style="border: 2px solid #3498db; border-radius: 15px; padding: 20px; width: 150px; text-align: center;">
68
- <h4 style="color:#2980b9;">AI Validation</h4>
69
- <p style="color:#7f8c8d; font-size: 12px;">Validate reports using AI, ensuring accuracy and preventing duplicates.</p>
70
- </div>
71
- <div style="border: 2px solid #3498db; border-radius: 15px; padding: 20px; width: 150px; text-align: center;">
72
- <h4 style="color:#2980b9;">Alerts</h4>
73
- <p style="color:#7f8c8d; font-size: 12px;">Notify authorities of repeated issues via email or SMS.</p>
74
- </div>
75
- <div style="border: 2px solid #3498db; border-radius: 15px; padding: 20px; width: 150px; text-align: center;">
76
- <h4 style="color:#2980b9;">Data Chat</h4>
77
- <p style="color:#7f8c8d; font-size: 12px;">Enable real-time discussion between consumers and authorities.</p>
78
- </div>
79
- </div>
80
- </div>
81
- """
82
-
83
  with gr.Blocks() as demo:
 
 
84
  with gr.Row():
85
- # Left column with chatbot
86
- with gr.Column(scale=2):
87
- gr.HTML(html_content)
88
- chatbot = gr.Chatbot()
89
- user_input = gr.Textbox(placeholder="Enter your message here...")
90
- chat_history = gr.State([]) # Initialize State here
91
- submit_btn = gr.Button("Submit")
92
- submit_btn.click(gradio_chat, inputs=[user_input, chat_history], outputs=[chatbot, chat_history]) # Include chat_history as input
93
- gr.Dataframe(value=data)
94
 
95
  # Launch the Gradio interface
96
  demo.launch()
 
32
  model_path = "gemini-1.5-flash"
33
  FoodSafetyAssistant = genai.GenerativeModel(model_path, system_instruction=system_instruction)
34
 
35
+ # Define the function to handle the user input
36
+ def respond(usertxt):
 
 
 
37
  # Get response from the assistant
38
+ response = FoodSafetyAssistant.send_message(usertxt)
39
+ return response.text # Return the generated response
 
 
 
 
 
40
 
41
  # Gradio interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  with gr.Blocks() as demo:
43
+ gr.Markdown("# Food Safety Assistant")
44
+
45
  with gr.Row():
46
+ # Text input on the left
47
+ user_input = gr.Textbox(label="Your Input", placeholder="Enter your message here...", lines=5)
48
+
49
+ # Text output on the right
50
+ output_text = gr.Textbox(label="Assistant Output", interactive=False, lines=5)
51
+
52
+ # Button to submit input and get output
53
+ submit_btn = gr.Button("Submit")
54
+ submit_btn.click(respond, inputs=user_input, outputs=output_text)
55
 
56
  # Launch the Gradio interface
57
  demo.launch()