Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- .env +1 -0
- app.py +65 -0
- requirements.txt +6 -0
.env
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
GOOGLE_API_KEY="AIzaSyCCR1ZGgDozOPB5CFDWxgMWAOkhOwmhrU4"
|
app.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from turtle import up
|
2 |
+
from dotenv import load_dotenv
|
3 |
+
import streamlit as st
|
4 |
+
import os
|
5 |
+
from PIL import Image
|
6 |
+
import google.generativeai as genai
|
7 |
+
|
8 |
+
load_dotenv()
|
9 |
+
|
10 |
+
genai.configure(api_key = os.getenv('GOOGLE_API_KEY'))
|
11 |
+
|
12 |
+
model = genai.GenerativeModel('gemini-pro-vision')
|
13 |
+
|
14 |
+
def get_response(input, image, prompt):
|
15 |
+
response = model.generate_content([input, image[0], prompt])
|
16 |
+
return response.parts
|
17 |
+
|
18 |
+
def input_image_setup(image):
|
19 |
+
if image is not None:
|
20 |
+
data = image.getvalue()
|
21 |
+
|
22 |
+
image_data = [
|
23 |
+
{
|
24 |
+
"mime_type": image.type,
|
25 |
+
"data": data
|
26 |
+
}
|
27 |
+
]
|
28 |
+
return image_data
|
29 |
+
|
30 |
+
else:
|
31 |
+
raise FileNotFoundError("NO FILE UPLOADED.")
|
32 |
+
|
33 |
+
st.set_page_config('Invoice Extractor')
|
34 |
+
st.header('Gemini Application')
|
35 |
+
|
36 |
+
|
37 |
+
prompt = st.text_input("Enter Prompt : " , key='prompt_input')
|
38 |
+
input = st.text_input("what do you want to know : " , key='user_input')
|
39 |
+
uploaded_file = st.file_uploader("Choose an image " , type=["jpg", "jpeg", "png"])
|
40 |
+
|
41 |
+
image = ""
|
42 |
+
if uploaded_file is not None:
|
43 |
+
image = Image.open(uploaded_file)
|
44 |
+
st.image(image, use_column_width=True)
|
45 |
+
|
46 |
+
submit = st.button("Tell me about the image")
|
47 |
+
|
48 |
+
if submit:
|
49 |
+
image_data = input_image_setup(uploaded_file)
|
50 |
+
response = get_response(input=input, image=image_data, prompt=prompt)
|
51 |
+
st.subheader("The response is : ")
|
52 |
+
st.write(response)
|
53 |
+
|
54 |
+
|
55 |
+
|
56 |
+
|
57 |
+
# You are an expert food analyst
|
58 |
+
|
59 |
+
# List all food items shown in image
|
60 |
+
|
61 |
+
|
62 |
+
# You are an invoice extractor
|
63 |
+
|
64 |
+
# what is total amount
|
65 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
google-generativeai
|
3 |
+
python-dotenv
|
4 |
+
langchain
|
5 |
+
PyPDF2
|
6 |
+
chromadb
|