rathodj080898 commited on
Commit
c277fb4
·
verified ·
1 Parent(s): 3fafd5e

Upload 2 files

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