MoRa2001 commited on
Commit
3075a87
1 Parent(s): 85e0df4
Files changed (2) hide show
  1. app.py +74 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Q&A Chatbot
2
+ #from langchain.llms import OpenAI
3
+ # take environment variables from .env.
4
+ import streamlit as st
5
+ import os
6
+ import pathlib
7
+ import textwrap
8
+ from PIL import Image
9
+
10
+
11
+ import google.generativeai as genai
12
+
13
+
14
+ os.getenv("GOOGLE_API_KEY")
15
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
16
+
17
+ ## Function to load OpenAI model and get respones
18
+
19
+ def get_gemini_response(input,image,prompt):
20
+ model = genai.GenerativeModel('gemini-pro-vision')
21
+ response = model.generate_content([input,image[0],prompt])
22
+ return response.text
23
+
24
+
25
+ def input_image_setup(uploaded_file):
26
+ # Check if a file has been uploaded
27
+ if uploaded_file is not None:
28
+ # Read the file into bytes
29
+ bytes_data = uploaded_file.getvalue()
30
+
31
+ image_parts = [
32
+ {
33
+ "mime_type": uploaded_file.type, # Get the mime type of the uploaded file
34
+ "data": bytes_data
35
+ }
36
+ ]
37
+ return image_parts
38
+ else:
39
+ raise FileNotFoundError("No file uploaded")
40
+
41
+
42
+ ##initialize our streamlit app
43
+
44
+ st.set_page_config(page_title="Image description APP")
45
+
46
+ st.header("Image description Application 🤖💬")
47
+ input=st.text_input("Input Prompt: ",key="input")
48
+ uploaded_file = st.file_uploader("Choose an image 🖼️💡 ...", type=["jpg", "jpeg", "png"])
49
+ image=""
50
+ if uploaded_file is not None:
51
+ image = Image.open(uploaded_file)
52
+ st.image(image, caption="Uploaded Image.", use_column_width=True)
53
+
54
+
55
+ submit=st.button("Tell me about the image")
56
+
57
+ input_prompt = """
58
+ You are an expert in nutritionist where you need to see the food items from the image
59
+ and calculate the total calories, also provide the details of every food items with calories intake
60
+ is below format
61
+
62
+ 1. Item 1 - no of calories
63
+ 2. Item 2 - no of calories
64
+ ----
65
+ ----
66
+ """
67
+
68
+ ## If ask button is clicked
69
+
70
+ if submit:
71
+ image_data = input_image_setup(uploaded_file)
72
+ response=get_gemini_response(input_prompt,image_data,input)
73
+ st.subheader("The Response is")
74
+ st.write(response)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ google-generativeai