irfan4108 commited on
Commit
cf7ee5c
·
verified ·
1 Parent(s): 87aade9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -17
app.py CHANGED
@@ -1,37 +1,44 @@
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)
 
 
 
 
 
1
  from dotenv import load_dotenv
2
  load_dotenv() # take environment variables from .env.
3
  import streamlit as st
4
  import os
5
  from PIL import Image
6
  import google.generativeai as genai
7
+
8
+ # Set the page configuration (must be the first Streamlit command)
9
+ st.set_page_config(page_title="Gemini Image Demo")
10
+
11
  os.getenv("GOOGLE_API_KEY")
12
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
13
+
14
+ ## Function to load OpenAI model and get response
15
+ def get_gemini_response(input, image):
16
  model = genai.GenerativeModel('gemini-1.5-pro')
17
+ if input != "":
18
+ response = model.generate_content([input, image])
19
  else:
20
+ response = model.generate_content(image)
21
  return response.text
22
+
23
+ ## Initialize our Streamlit app
24
  st.header("Food Analysis")
25
 
26
  input1 = """
27
+ You are a specialized in food analysis for Indian cuisine and image recognition. Given an image of an Indian food thali, your job is to analyze and report on the following 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, rotten, or spoiled. Use descriptive terms to specify the condition of each dish. Quantity Estimation: Estimate the quantity of each item in the thali in grams and provide an approximate percentage for each detected item to reflect its quantity relative to the entire plate. Sufficiency Assessment: Evaluate if the total quantity and variety of food items in the thali are sufficient for a 14-year-old child, considering standard dietary needs and portion sizes. Present the results in a structured table format with columns for the Detected Dish Name, Freshness Status (e.g., Fresh, Slightly Stale, Overcooked, Rotten, Spoiled), Quantity in Grams, and Quantity Percentage (e.g., Dal: 150g, 15%). Ensure accuracy in identifying each dish, assessing freshness, estimating quantity, and evaluating sufficiency.
28
  """
29
+ input = st.text_input("Input Prompt: ", key="input", placeholder="Optional")
30
  uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
31
+ image = ""
32
  if uploaded_file is not None:
33
  image = Image.open(uploaded_file)
34
  st.image(image, caption="Uploaded Image.", use_column_width=True)
35
+
36
+ submit = st.button("Check the Food Quality")
37
+
38
+ ## If submit button is clicked
39
  if submit:
40
+ with st.spinner("Please wait while assessing the food quality..."):
41
+ response = get_gemini_response(input1 + input, image)
42
+ st.subheader("The Response is")
43
+ st.write(f"Prompt Is : {input1 + input}")
44
+ st.write(response)