Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +46 -0
- requirements.txt +6 -0
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dotenv import load_dotenv
|
| 2 |
+
load_dotenv()
|
| 3 |
+
import streamlit as st
|
| 4 |
+
import os
|
| 5 |
+
import google.generativeai as genai
|
| 6 |
+
from PIL import Image
|
| 7 |
+
|
| 8 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 9 |
+
# load gemini model
|
| 10 |
+
model=genai.GenerativeModel("gemini-pro-vision")
|
| 11 |
+
def get_gemini_response(input,image,prompt):
|
| 12 |
+
response=model.generate_content([input,image[0],prompt])
|
| 13 |
+
return response.text
|
| 14 |
+
def input_image_setup(uploaded_img):
|
| 15 |
+
if uploaded_img is not None:
|
| 16 |
+
bytes_data = uploaded_img.getvalue()
|
| 17 |
+
image_parts=[
|
| 18 |
+
{
|
| 19 |
+
"mime_type": uploaded_img.type,
|
| 20 |
+
"data": bytes_data
|
| 21 |
+
}
|
| 22 |
+
]
|
| 23 |
+
return image_parts
|
| 24 |
+
else:
|
| 25 |
+
raise FileNotFoundError("Image not found")
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
st.set_page_config(page_title="Invoice extractor", page_icon="🔮")
|
| 29 |
+
st.title("Gemini llm application")
|
| 30 |
+
input = st.text_input("Ask a question", key="input")
|
| 31 |
+
uploaded_img = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
| 32 |
+
image=""
|
| 33 |
+
if uploaded_img is not None:
|
| 34 |
+
image = Image.open(uploaded_img)
|
| 35 |
+
st.image(image, caption="Uploaded Image.", use_column_width=True)
|
| 36 |
+
submit=st.button("Submit")
|
| 37 |
+
|
| 38 |
+
input_prompt="""
|
| 39 |
+
You are expert in understanding invoices. We will show you an invoice and you have to answer the following questions based on the invoice:
|
| 40 |
+
|
| 41 |
+
"""
|
| 42 |
+
if submit:
|
| 43 |
+
image_data=input_image_setup(uploaded_img)
|
| 44 |
+
response=get_gemini_response(input_prompt,image_data,input)
|
| 45 |
+
st.subheader("Response:")
|
| 46 |
+
st.write(response)
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
google-generativeai
|
| 3 |
+
python-dotenv
|
| 4 |
+
langchain
|
| 5 |
+
PyPDF2
|
| 6 |
+
chromadb
|