File size: 1,357 Bytes
2202678
5752036
 
 
 
500f282
e26cb3a
2202678
 
 
aabdb39
6e48f8d
607408e
2202678
1408b7d
 
48d51b7
 
 
 
0614c64
f48f1aa
2202678
5752036
 
27b7365
83380bb
2202678
 
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

import gradio as gr
import pandas as pd
import cv2
import easyocr
import google.generativeai as genai

reader= easyocr.Reader(['en'])
API_KEY = 'AIzaSyC85O_R-H8VhRpxAEj7iUAw0o7NCNJ_VmE'
genai.configure(api_key = API_KEY)

allergies = "peanuts,dairy,gluten"

def ocr_genai(image):
    results=reader.readtext(image)
    results=pd.DataFrame(results,columns=['bbox','text','conf'])
    model = genai.GenerativeModel('gemini-pro')
    chat = model.start_chat(history = [])
    instruction = ""
    question = ' '.join(results.text.astype(str))
    response = chat.send_message(question+f"The ingredients are extracted from EasyOCR and may not be well formatted. Extract only the ingredients. The user is allergic to {allergies}. For each ingredient, determine if it poses a risk to the user. If it does, classify the risk level as 'High', 'Moderate', or 'Low', and provide a one-line description explaining why and how it poses a risk. The response should be in text format with fields 'ingredient' and 'risk'. The 'risk' field should contain both the risk level and the description.")
    return response.text

title = "SafeSpoon"
description = "Upload an image of ingredients"
inputs = gr.Image()
outputs = gr.Textbox(label='Results',lines = 20)
interface = gr.Interface(fn=ocr_genai, inputs=inputs, outputs=outputs,title=title)
interface.launch(share=True)