File size: 3,517 Bytes
64705ab
133dff0
 
 
bfa42bd
133dff0
 
 
 
 
f906c30
133dff0
 
 
 
 
 
 
62f2cca
133dff0
 
 
 
 
55f9440
ca76381
e838b4f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133dff0
7e6a155
e838b4f
f906c30
55f9440
 
 
 
74019c1
7430dca
41bf181
c7be83f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import gradio as gr
import pandas as pd
import google.generativeai as genai
import kagglehub
import os

path = kagglehub.dataset_download("fahmidachowdhury/food-adulteration-dataset")
dataset_file = os.listdir(path)[0]
path = os.path.join(path, dataset_file)

gemapi = os.getenv("GeminiApi")
genai.configure(api_key=gemapi)

data = pd.read_csv(path)

system_instruction = f"""
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())}
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.
You will try to help the customer launch a feedback review whenever they complain. You are to prepare a "markdown" report, which is then detailed and can be sent to the company or restaurant.
"""

model_path = "gemini-1.5-flash"
FoodSafetyAssistant = genai.GenerativeModel(model_path, system_instruction=system_instruction)

def respond(usertxt):
    response = FoodSafetyAssistant.generate_content(contents=[usertxt])
    return response.text

html_content = """
<div style="background-color:#f9f9f9; padding:20px; border-radius:10px;">
    <h1 style="color:#34495e;">Food Safety Assistant</h1>
    <h3 style="color:#2c3e50;">Your AI-Powered Assistant for Food Safety</h3>
    <p style="color:#7f8c8d;">
        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.
    </p>
    <h4 style="color:#e74c3c; text-align:center;">Core Functionalities</h4>
    <div style="display:flex; justify-content: space-around; align-items:center; margin-top:20px;">
        <div style="border: 2px solid #3498db; border-radius: 15px; padding: 20px; width: 150px; text-align: center;">
            <h4 style="color:#2980b9;">Report Issues</h4>
            <p style="color:#7f8c8d; font-size: 12px;">Submit details like the restaurant name and the issue, anonymously.</p>
        </div>
        <div style="border: 2px solid #3498db; border-radius: 15px; padding: 20px; width: 150px; text-align: center;">
            <h4 style="color:#2980b9;">AI Validation</h4>
            <p style="color:#7f8c8d; font-size: 12px;">Validate reports using AI, ensuring accuracy and preventing duplicates.</p>
        </div>
        <div style="border: 2px solid #3498db; border-radius: 15px; padding: 20px; width: 150px; text-align: center;">
            <h4 style="color:#2980b9;">Alerts</h4>
            <p style="color:#7f8c8d; font-size: 12px;">Notify authorities of repeated issues via email or SMS.</p>
        </div>
        <div style="border: 2px solid #3498db; border-radius: 15px; padding: 20px; width: 150px; text-align: center;">
            <h4 style="color:#2980b9;">Data Chat</h4>
            <p style="color:#7f8c8d; font-size: 12px;">Enable real-time discussion between consumers and authorities.</p>
        </div>
    </div>
</div>
"""

with gr.Blocks() as demo:
    gr.HTML(html_content)
    with gr.Row():
        user_input = gr.Textbox(label="Your Input", placeholder="Enter your message here...", lines=5)
        output_text = gr.Textbox(label="Assistant Output", interactive=False, lines=5)
    submit_btn = gr.Button("Submit")
    submit_btn.click(respond, inputs=user_input, outputs=output_text)
    gr.Dataframe(value = data)

demo.launch()