Spaces:
Sleeping
Sleeping
init
Browse files
app.py
CHANGED
|
@@ -1,41 +1,46 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
import google.generativeai as genai
|
| 4 |
-
|
| 5 |
import kagglehub
|
|
|
|
|
|
|
|
|
|
| 6 |
path = kagglehub.dataset_download("fahmidachowdhury/food-adulteration-dataset")
|
| 7 |
-
gemapi = "AIzaSyAmDOBWfGuEju0oZyUIcn_H0k8XW0cTP7k"
|
| 8 |
-
genai.configure(api_key = gemapi)
|
| 9 |
|
| 10 |
-
|
| 11 |
-
os.listdir(path)
|
| 12 |
-
path =
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 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 Indian context. You act as
|
| 19 |
-
You will try to help the customer launch a feedback review whenever they complain. You are to prepare a "markdown" report which is detailed and
|
| 20 |
-
In case of a complaint or a grievance,
|
| 21 |
-
Once the customer asks you to show them the markdown report, you will use the information given to you to generate
|
| 22 |
-
You will ask the customer a single question at a time, which is
|
| 23 |
"""
|
| 24 |
|
|
|
|
| 25 |
model_path = "gemini-1.5-flash"
|
| 26 |
-
FoodSafetyAssistant = genai.GenerativeModel(model_path, system_instruction
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
chat = FoodSafetyAssistant.start_chat(history
|
| 31 |
response = chat.send_message(usertxt)
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
demo = gr.ChatInterface(
|
| 36 |
-
respond
|
| 37 |
-
)
|
| 38 |
|
|
|
|
|
|
|
| 39 |
|
|
|
|
| 40 |
if __name__ == "__main__":
|
| 41 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
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 = "AIzaSyAmDOBWfGuEju0oZyUIcn_H0k8XW0cTP7k"
|
| 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.
|
| 25 |
+
You will try to help the customer launch a feedback review whenever they complain. You are to prepare a "markdown" report, which is detailed and can be sent to the company or restaurant.
|
| 26 |
+
In case of a complaint or a grievance, you will act like a detective gathering necessary information from the user until you are satisfied. Once you gather all the info, you are supposed to generate a markdown report.
|
| 27 |
+
Once the customer asks you to show them the markdown report, you will use the information given to you to generate it.
|
| 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 chat
|
| 36 |
+
def respond(usertxt, chat_history=[]):
|
| 37 |
+
chat = FoodSafetyAssistant.start_chat(history=chat_history)
|
| 38 |
response = chat.send_message(usertxt)
|
| 39 |
+
return response.text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
# Gradio interface
|
| 42 |
+
demo = gr.ChatInterface(fn=respond)
|
| 43 |
|
| 44 |
+
# Launch the Gradio app
|
| 45 |
if __name__ == "__main__":
|
| 46 |
demo.launch()
|