Spaces:
Sleeping
Sleeping
| 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) | |