Spaces:
Running
Running
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(image): | |
model = genai.GenerativeModel('gemini-1.5-flash') | |
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]) | |
return response.text | |
st.set_page_config(page_title="Prompt generation from image") | |
st.header("Application") | |
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(image) | |
st.subheader("The Generated Prompt is") | |
st.write(response) |