aaronmat1905 commited on
Commit
41bf181
·
verified ·
1 Parent(s): 7430dca
Files changed (1) hide show
  1. app.py +11 -23
app.py CHANGED
@@ -13,7 +13,6 @@ path = os.path.join(path, dataset_file)
13
 
14
  # Configure Google Gemini API
15
  gemapi = os.getenv("GeminiApi")
16
-
17
  genai.configure(api_key=gemapi)
18
 
19
  # Load the dataset
@@ -33,9 +32,6 @@ You will ask the customer a single question at a time, which is relevant, and yo
33
  model_path = "gemini-1.5-flash"
34
  FoodSafetyAssistant = genai.GenerativeModel(model_path, system_instruction=system_instruction)
35
 
36
- # Track chat history globally
37
- chat_history = []
38
-
39
  # Define the function to handle the chat
40
  def respond(usertxt, chat_history):
41
  # Initialize chat with the previous history
@@ -44,46 +40,38 @@ def respond(usertxt, chat_history):
44
  # Get response from the assistant
45
  response = chat.send_message(usertxt)
46
 
47
- # Append both user input and response to the chat history for context in the next interaction
48
  chat_history.append({"role": "user", "content": usertxt})
49
  chat_history.append({"role": "assistant", "content": response.text})
50
 
51
- return response.text, chat_history
52
 
53
  # Gradio interface
54
  def gradio_chat(usertxt, chat_history):
55
  response, updated_history = respond(usertxt, chat_history)
56
- return response, updated_history
 
57
  html_content = """
58
  <div style="background-color:#f9f9f9; padding:20px; border-radius:10px;">
59
- <!-- Project Title and Problem Statement Section -->
60
  <h1 style="color:#34495e;">Food Safety Assistant</h1>
61
  <h3 style="color:#2c3e50;">Your AI-Powered Assistant for Food Safety</h3>
62
- <!-- Short Intro About AI-Chat -->
63
  <p style="color:#7f8c8d;">
64
  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.
65
  </p>
66
- <!-- Core Functionalities Title -->
67
  <h4 style="color:#e74c3c; text-align:center;">Core Functionalities</h4>
68
- <!-- Functionality Boxes in a Flex Layout -->
69
  <div style="display:flex; justify-content: space-around; align-items:center; margin-top:20px;">
70
- <!-- Functionality 1 -->
71
  <div style="border: 2px solid #3498db; border-radius: 15px; padding: 20px; width: 150px; text-align: center;">
72
  <h4 style="color:#2980b9;">Report Issues</h4>
73
  <p style="color:#7f8c8d; font-size: 12px;">Submit details like the restaurant name and the issue, anonymously.</p>
74
  </div>
75
-
76
- <!-- Functionality 2 -->
77
  <div style="border: 2px solid #3498db; border-radius: 15px; padding: 20px; width: 150px; text-align: center;">
78
  <h4 style="color:#2980b9;">AI Validation</h4>
79
  <p style="color:#7f8c8d; font-size: 12px;">Validate reports using AI, ensuring accuracy and preventing duplicates.</p>
80
  </div>
81
- <!-- Functionality 3 -->
82
  <div style="border: 2px solid #3498db; border-radius: 15px; padding: 20px; width: 150px; text-align: center;">
83
  <h4 style="color:#2980b9;">Alerts</h4>
84
  <p style="color:#7f8c8d; font-size: 12px;">Notify authorities of repeated issues via email or SMS.</p>
85
  </div>
86
- <!-- Functionality 4 -->
87
  <div style="border: 2px solid #3498db; border-radius: 15px; padding: 20px; width: 150px; text-align: center;">
88
  <h4 style="color:#2980b9;">Data Chat</h4>
89
  <p style="color:#7f8c8d; font-size: 12px;">Enable real-time discussion between consumers and authorities.</p>
@@ -94,15 +82,15 @@ html_content = """
94
 
95
  with gr.Blocks() as demo:
96
  with gr.Row():
 
97
  with gr.Column(scale=2):
98
  gr.HTML(html_content)
99
- chatbot = gr.Chatbot() # Chatbot output
100
  user_input = gr.Textbox(placeholder="Enter your message here...")
101
- chat_history = gr.State([]) # Initialize State for chat history
102
-
103
  submit_btn = gr.Button("Submit")
104
- submit_btn.click(gradio_chat, inputs=[user_input, chat_history], outputs=[chatbot, chat_history])
105
-
106
- gr.Dataframe(value=data) # Display the dataset
107
 
108
- demo.launch()
 
 
13
 
14
  # Configure Google Gemini API
15
  gemapi = os.getenv("GeminiApi")
 
16
  genai.configure(api_key=gemapi)
17
 
18
  # Load the dataset
 
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
 
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>
 
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()