Ankit93 commited on
Commit
cf3981b
·
verified ·
1 Parent(s): 7aa5968

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +45 -0
  2. requirements.txt +14 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pathlib
2
+ import textwrap
3
+ import streamlit as st
4
+ import google.generativeai as genai
5
+ from PIL import Image
6
+ from IPython.display import Markdown
7
+ from IPython.display import display
8
+
9
+ genai.configure(api_key='AIzaSyA_XykKxC4aSi0af9VH5uP2eQlp9Nh25Ds')
10
+ model = genai.GenerativeModel(model_name="models/gemini-pro-vision")
11
+
12
+ def geminin_response(input,image,prompt):
13
+ response = model.generate_content([input,image[0],prompt])
14
+ return response.text
15
+
16
+ st.set_page_config(page_title="Multi Language Text Extractor")
17
+ st.header("Gemini Application")
18
+ input = st.text_input("Input Query :",key='input')
19
+ uploaded_file = st.file_uploader("Choose an image:",type=['.jpg','.pdf','.jpeg','png'])
20
+
21
+ image=''
22
+ if uploaded_file is not None:
23
+ format = ['.jpg','.jpeg','png']
24
+ for form in format:
25
+ if str(uploaded_file.name).endswith(form):
26
+ image = Image.open(uploaded_file)
27
+ st.image(image,caption='Uploaded Image!!!',use_column_width=True)
28
+ elif str(uploaded_file.name).endswith('.pdf'):
29
+ st.warning('Please Upload Images !!!', icon="⚠️")
30
+ break
31
+
32
+ submit = st.button("Tell me about invoice")
33
+ input_prompt = "We are uploading an image and you will have to answer any questions based on image"
34
+ def input_image_details(uploaded_file):
35
+ bytes_data = uploaded_file.getvalue()
36
+ image_parts = [{
37
+ "mime_type":uploaded_file.type,
38
+ "data":bytes_data
39
+ }]
40
+ return image_parts
41
+ if submit:
42
+ image_data = input_image_details(uploaded_file)
43
+ resp = geminin_response(input_prompt,image_data,input)
44
+ st.subheader("The Response is:")
45
+ st.write(resp)
requirements.txt ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ langchain
2
+ openai
3
+ huggingface_hub
4
+ python-dotenv
5
+ streamlit
6
+ cassio
7
+ tiktoken
8
+ datasets
9
+ PyPDF2
10
+ pypdf
11
+ unstructured
12
+ pinecone-client
13
+ chromadb
14
+ !pip3 install -q -U google-generativeai