Image.to.prompt / app.py
shikharyashmaurya's picture
Update app.py
0a20eb1 verified
raw
history blame
1.53 kB
import streamlit as st
import os
from PIL import Image
import google.generativeai as genai
secret_key = os.getenv("SECRET_KEY")
genai.configure(api_key=secret_key)
def get_gemini_response(input,image):
model = genai.GenerativeModel('gemini-pro-vision')
if input!="":
input='''You are a prompt generator.You will get an image.
Your work is to write a prompt such that an image generator model would create most identical picture
as the image given to you'''
response = model.generate_content([input,image])
else:
new_input=''
new_input='''You are a prompt generator.You will get an image.
Your work is to write a prompt such that an image generator model would create most identical picture
as the image given to you and the extra feature provide that you mant in image are as follows '''+input
response = model.generate_content([new_input,image])
return response.text
st.set_page_config(page_title="Prompt generation from image")
st.header("Application")
input=st.text_input("Any special change in image you want to specify: ",key="input")
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
image=""
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption="Uploaded Image.", use_column_width=True)
submit=st.button("Generate Prompt")
if submit:
response=get_gemini_response(input,image)
st.subheader("The Generated Prompt is")
st.write(response)