Lalitr's picture
Update app.py
2d38233 verified
import google.generativeai as genai
import streamlit as st
import numpy as np
from PIL import Image
#from dotenv import load_dotenv
#load_dotenv()
import json
import os
GOOGLE_API_KEY=os.getenv('GOOGLE_API_KEY')
genai.configure(api_key=GOOGLE_API_KEY)
st.set_page_config(page_title='Description Generator',
page_icon=':milky_way:',
layout='centered',
initial_sidebar_state='collapsed'
)
st.header('Image Description Generator(Share Image get description)')
uploaded_file = st.file_uploader("Choose a file", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
# To read file as bytes:
#bytes_data = uploaded_file.getvalue()
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
st.image(uploaded_file)
#from IPython.display import Image
img = Image.open(uploaded_file)
prompt = """This image contains a sketch.
try to identify and Describe the sketch as thoroughly as possible based on what you
see in the image, making sure to note all of the features. Return output in json format:
{description: description, features: [feature1, feature2, feature3, etc]}"""
submit=st.button('Generate')
if submit:
model = genai.GenerativeModel('gemini-1.5-flash')
response = model.generate_content([prompt, img])
response=json.loads(response.text)
st.write((response['description']))
number=1
for feature in response['features']:
st.write("Feature "+str(number)+" : "+str(feature))
number+=1