Spaces:
Sleeping
Sleeping
init
Browse files
app.py
CHANGED
|
@@ -4,21 +4,15 @@ import google.generativeai as genai
|
|
| 4 |
import kagglehub
|
| 5 |
import os
|
| 6 |
|
| 7 |
-
# Download the Kaggle dataset
|
| 8 |
path = kagglehub.dataset_download("fahmidachowdhury/food-adulteration-dataset")
|
| 9 |
-
|
| 10 |
-
# List the files in the dataset folder and assign the first one (assuming it's the desired file)
|
| 11 |
dataset_file = os.listdir(path)[0]
|
| 12 |
path = os.path.join(path, dataset_file)
|
| 13 |
|
| 14 |
-
# Configure Google Gemini API
|
| 15 |
gemapi = os.getenv("GeminiApi")
|
| 16 |
genai.configure(api_key=gemapi)
|
| 17 |
|
| 18 |
-
# Load the dataset
|
| 19 |
data = pd.read_csv(path)
|
| 20 |
|
| 21 |
-
# Define the system instructions for the model
|
| 22 |
system_instruction = f"""
|
| 23 |
You are a public assistant who specializes in food safety. You look at data and explain to the user any question they ask; here is your data: {str(data.to_json())}
|
| 24 |
You are also a food expert in the Indian context. You act as a representative of the government or public agencies, always keeping the needs of the people at the forefront.
|
|
@@ -28,30 +22,48 @@ Once the customer asks you to show them the markdown report, you will use the in
|
|
| 28 |
You will ask the customer a single question at a time, which is relevant, and you will not repeat another question until you've generated the report.
|
| 29 |
"""
|
| 30 |
|
| 31 |
-
# Initialize the model
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
# Gradio interface
|
| 42 |
with gr.Blocks() as demo:
|
| 43 |
-
gr.
|
| 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()
|
|
|
|
| 4 |
import kagglehub
|
| 5 |
import os
|
| 6 |
|
|
|
|
| 7 |
path = kagglehub.dataset_download("fahmidachowdhury/food-adulteration-dataset")
|
|
|
|
|
|
|
| 8 |
dataset_file = os.listdir(path)[0]
|
| 9 |
path = os.path.join(path, dataset_file)
|
| 10 |
|
|
|
|
| 11 |
gemapi = os.getenv("GeminiApi")
|
| 12 |
genai.configure(api_key=gemapi)
|
| 13 |
|
|
|
|
| 14 |
data = pd.read_csv(path)
|
| 15 |
|
|
|
|
| 16 |
system_instruction = f"""
|
| 17 |
You are a public assistant who specializes in food safety. You look at data and explain to the user any question they ask; here is your data: {str(data.to_json())}
|
| 18 |
You are also a food expert in the Indian context. You act as a representative of the government or public agencies, always keeping the needs of the people at the forefront.
|
|
|
|
| 22 |
You will ask the customer a single question at a time, which is relevant, and you will not repeat another question until you've generated the report.
|
| 23 |
"""
|
| 24 |
|
|
|
|
| 25 |
model_path = "gemini-1.5-flash"
|
| 26 |
FoodSafetyAssistant = genai.GenerativeModel(model_path, system_instruction=system_instruction)
|
| 27 |
|
|
|
|
| 28 |
def respond(usertxt):
|
|
|
|
| 29 |
response = FoodSafetyAssistant.send_message(usertxt)
|
| 30 |
+
return response.text
|
| 31 |
+
|
| 32 |
+
html_content = """
|
| 33 |
+
<div style="background-color:#f9f9f9; padding:20px; border-radius:10px;">
|
| 34 |
+
<h1 style="color:#34495e;">Food Safety Assistant</h1>
|
| 35 |
+
<h3 style="color:#2c3e50;">Your AI-Powered Assistant for Food Safety</h3>
|
| 36 |
+
<p style="color:#7f8c8d;">
|
| 37 |
+
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.
|
| 38 |
+
</p>
|
| 39 |
+
<h4 style="color:#e74c3c; text-align:center;">Core Functionalities</h4>
|
| 40 |
+
<div style="display:flex; justify-content: space-around; align-items:center; margin-top:20px;">
|
| 41 |
+
<div style="border: 2px solid #3498db; border-radius: 15px; padding: 20px; width: 150px; text-align: center;">
|
| 42 |
+
<h4 style="color:#2980b9;">Report Issues</h4>
|
| 43 |
+
<p style="color:#7f8c8d; font-size: 12px;">Submit details like the restaurant name and the issue, anonymously.</p>
|
| 44 |
+
</div>
|
| 45 |
+
<div style="border: 2px solid #3498db; border-radius: 15px; padding: 20px; width: 150px; text-align: center;">
|
| 46 |
+
<h4 style="color:#2980b9;">AI Validation</h4>
|
| 47 |
+
<p style="color:#7f8c8d; font-size: 12px;">Validate reports using AI, ensuring accuracy and preventing duplicates.</p>
|
| 48 |
+
</div>
|
| 49 |
+
<div style="border: 2px solid #3498db; border-radius: 15px; padding: 20px; width: 150px; text-align: center;">
|
| 50 |
+
<h4 style="color:#2980b9;">Alerts</h4>
|
| 51 |
+
<p style="color:#7f8c8d; font-size: 12px;">Notify authorities of repeated issues via email or SMS.</p>
|
| 52 |
+
</div>
|
| 53 |
+
<div style="border: 2px solid #3498db; border-radius: 15px; padding: 20px; width: 150px; text-align: center;">
|
| 54 |
+
<h4 style="color:#2980b9;">Data Chat</h4>
|
| 55 |
+
<p style="color:#7f8c8d; font-size: 12px;">Enable real-time discussion between consumers and authorities.</p>
|
| 56 |
+
</div>
|
| 57 |
+
</div>
|
| 58 |
+
</div>
|
| 59 |
+
"""
|
| 60 |
|
|
|
|
| 61 |
with gr.Blocks() as demo:
|
| 62 |
+
gr.HTML(html_content)
|
|
|
|
| 63 |
with gr.Row():
|
|
|
|
| 64 |
user_input = gr.Textbox(label="Your Input", placeholder="Enter your message here...", lines=5)
|
|
|
|
|
|
|
| 65 |
output_text = gr.Textbox(label="Assistant Output", interactive=False, lines=5)
|
|
|
|
|
|
|
| 66 |
submit_btn = gr.Button("Submit")
|
| 67 |
submit_btn.click(respond, inputs=user_input, outputs=output_text)
|
| 68 |
|
|
|
|
| 69 |
demo.launch()
|