Spaces:
Runtime error
Runtime error
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,70 +0,0 @@
|
|
| 1 |
-
### Invoice extractor
|
| 2 |
-
|
| 3 |
-
##Importing All the modules
|
| 4 |
-
import streamlit as st
|
| 5 |
-
import os
|
| 6 |
-
from PIL import Image
|
| 7 |
-
import google.generativeai as genai
|
| 8 |
-
from dotenv import load_dotenv
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
# Load all environment Variables
|
| 12 |
-
load_dotenv()
|
| 13 |
-
|
| 14 |
-
##Configuring the api key
|
| 15 |
-
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 16 |
-
|
| 17 |
-
## Function to load Gemini Vison Pro Vision Model and Get response
|
| 18 |
-
|
| 19 |
-
def get_gemini_response(input,image,prompt):
|
| 20 |
-
|
| 21 |
-
##Loading the desired Model
|
| 22 |
-
model= genai.GenerativeModel("gemini-pro-vision")
|
| 23 |
-
response=model.generate_content([input,image[0],prompt])
|
| 24 |
-
return response.text
|
| 25 |
-
|
| 26 |
-
## Function to extract data from Image Uploaded
|
| 27 |
-
def input_image_setup(uploaded_file):
|
| 28 |
-
# Check if a file has been uploaded
|
| 29 |
-
if uploaded_file is not None:
|
| 30 |
-
# Read the file into bytes
|
| 31 |
-
bytes_data = uploaded_file.getvalue()
|
| 32 |
-
|
| 33 |
-
image_parts = [
|
| 34 |
-
{
|
| 35 |
-
"mime_type": uploaded_file.type, # Get the mime type of the uploaded file
|
| 36 |
-
"data": bytes_data
|
| 37 |
-
}
|
| 38 |
-
]
|
| 39 |
-
return image_parts
|
| 40 |
-
else:
|
| 41 |
-
raise FileNotFoundError("No file uploaded")
|
| 42 |
-
|
| 43 |
-
# Initializing our Streamlit Prompt
|
| 44 |
-
|
| 45 |
-
st.set_page_config(page_title="Gemini Image Demo")
|
| 46 |
-
|
| 47 |
-
st.header("Gemini Application")
|
| 48 |
-
input=st.text_input("Input Prompt: ",key="input")
|
| 49 |
-
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
| 50 |
-
image=""
|
| 51 |
-
if uploaded_file is not None:
|
| 52 |
-
image = Image.open(uploaded_file)
|
| 53 |
-
st.image(image, caption="Uploaded Image.", use_column_width=True)
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
submit=st.button("Tell me about the image")
|
| 57 |
-
|
| 58 |
-
## DEFINING A SYSTEM PROMPT
|
| 59 |
-
|
| 60 |
-
input_prompt = "You are an expert in understanding invoices.You will receive invoices as input images and you will have to answer question based on the input image."
|
| 61 |
-
|
| 62 |
-
if submit:
|
| 63 |
-
image_data = input_image_setup(uploaded_file)
|
| 64 |
-
response = get_gemini_response(input_prompt,image_data,input)
|
| 65 |
-
|
| 66 |
-
st.subheader("The Response Generated by your model Gemini Pro Vision is: ")
|
| 67 |
-
st.write(response)
|
| 68 |
-
# st.write("Follow me on LinkedIn: https://www.linkedin.com/in/mohammed-musharraf-44a98a280/ ")
|
| 69 |
-
|
| 70 |
-
st.balloons()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|