irfan4108 commited on
Commit
acea49b
·
verified ·
1 Parent(s): bc439d8

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Q&A Chatbot
2
+ #from langchain.llms import OpenAI
3
+ from dotenv import load_dotenv
4
+ load_dotenv() # take environment variables from .env.
5
+ import streamlit as st
6
+ import os
7
+ from PIL import Image
8
+ import google.generativeai as genai
9
+ os.getenv("GOOGLE_API_KEY")
10
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
11
+ ## Function to load OpenAI model and get respones
12
+ def get_gemini_response(input,image):
13
+ model = genai.GenerativeModel('gemini-1.5-pro')
14
+ if input!="":
15
+ response = model.generate_content([input,image])
16
+ else:
17
+ response = model.generate_content(image)
18
+ return response.text
19
+ ##initialize our streamlit app
20
+ st.set_page_config(page_title="Gemini Image Demo")
21
+ st.header("Food Analysis")
22
+
23
+ input1 = """
24
+ You are a food analysis AI specialized in Indian cuisine and image recognition. Given an image of an Indian food thali, your job is to analyze and report on three key aspects: Dish Detection: Identify and label each distinct dish in the thali. Recognize common Indian food items (such as roti, rice, dal, curries, vegetables, pickles, and sweets) with high accuracy. Use visual details like shape, color, and garnish to distinguish between similar-looking items. Freshness and Condition Assessment: Assess the freshness of each item by examining visual cues such as color, texture, and moisture. Indicate whether each item appears fresh, slightly stale, overcooked, or rotten, and use descriptive terms to specify the condition of each dish. Quantity Estimation: Estimate the proportion of each item in the thali as a percentage of the overall plate content. Provide an approximate percentage for each detected item to reflect its quantity relative to the entire plate. Present the results in a structured table format with columns for the Detected Dish Name, Freshness Status (e.g., Fresh, Slightly Stale, Overcooked, Rotten), and Quantity Percentage (e.g., Dal: 15%, Rice: 20%, etc.). Ensure accuracy in identifying each dish, assessing freshness, and estimating quantity.
25
+ """
26
+ input=st.text_input("Input Prompt: ",key="input", placeholder="Optional")
27
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
28
+ image=""
29
+ if uploaded_file is not None:
30
+ image = Image.open(uploaded_file)
31
+ st.image(image, caption="Uploaded Image.", use_column_width=True)
32
+ submit=st.button("Tell me about the image")
33
+ ## If ask button is clicked
34
+ if submit:
35
+ response=get_gemini_response(input1 + input,image)
36
+ st.subheader("The Response is")
37
+ st.write(response)