File size: 1,685 Bytes
cf3981b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e149839
cf3981b
 
4d5ba42
 
 
 
 
 
 
cf3981b
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import pathlib
import textwrap
import streamlit as st
import google.generativeai as genai
from PIL import Image
from IPython.display import Markdown
from IPython.display import display

genai.configure(api_key='AIzaSyA_XykKxC4aSi0af9VH5uP2eQlp9Nh25Ds')
model = genai.GenerativeModel(model_name="models/gemini-pro-vision")

def geminin_response(input,image,prompt):
    response = model.generate_content([input,image[0],prompt])
    return response.text

st.set_page_config(page_title="Multi Language Text Extractor")
st.header("Gemini Application")
input = st.text_input("Input Query :",key='input')
uploaded_file = st.file_uploader("Choose an image:",type=['.jpg','.pdf','.jpeg','png'])

image=''
if uploaded_file is not None:
    format = ['.jpg','.jpeg','png']
    for form in format:
        if str(uploaded_file.name).endswith(form):
            image = Image.open(uploaded_file)
            st.image(image,caption='Uploaded Image!!!',use_column_width=True)
        elif str(uploaded_file.name).endswith('.pdf'):
            st.warning('Please Upload Images !!!', icon="⚠️")
            break

submit = st.button("Extract Information about this image")
input_prompt = "We are uploading an image and you will have to answer any questions based on image"
def input_image_details(uploaded_file):
    if uploaded_file:
        bytes_data = uploaded_file.getvalue()
        image_parts = [{
            "mime_type":uploaded_file.type,
            "data":bytes_data
        }]
        return image_parts
if submit:
    image_data = input_image_details(uploaded_file)
    resp = geminin_response(input_prompt,image_data,input)
    st.subheader("The Response is:")
    st.write(resp)