from dotenv import load_dotenv import streamlit as st import os import google.generativeai as genai from PIL import Image load_dotenv() genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) # Function to get response from Gemini model def get_gemini_response(input_prompt, image_data, genre, length, language, mood): model = genai.GenerativeModel('gemini-1.5-flash') # If both image and text are provided if image_data and input_prompt: full_prompt = f""" You are a famous creative writer. Look at the image provided and also consider the following prompt: "{input_prompt}". Create a {length} {genre} in {language}. The {genre} should be {mood}, based on both the image and the prompt, and contain realistic and emotional elements. """ response = model.generate_content([full_prompt, image_data[0]]) # If only image is provided elif image_data: full_prompt = f""" You are a famous creative writer. Look at the image provided and create a {length} {genre} in {language}. The {genre} should be {mood}. The {genre} should be based on the image and contain realistic and emotional elements. """ response = model.generate_content([full_prompt, image_data[0]]) # If only text is provided elif input_prompt: full_prompt = f""" You are a creative writer. Create a {length} {genre} in {language}. The {genre} should be {mood}. The {genre} should be based on the following prompt: "{input_prompt}" Make sure it contains realistic and emotional elements. """ response = model.generate_content([full_prompt]) # If neither image nor text is provided else: raise ValueError("Please provide either an image or a text prompt.") # Check if response is valid and return text if response and response.parts: return response.parts[0].text else: raise ValueError("Sorry, please try a different combination of inputs.") # Function to setup uploaded image def input_image_setup(uploaded_file): if uploaded_file is not None: bytes_data = uploaded_file.getvalue() image_parts = [ { "mime_type": uploaded_file.type, "data": bytes_data } ] return image_parts else: return None # Initialize Streamlit app st.set_page_config(page_title="Poetic Vision", page_icon=":pencil:", layout="wide") # Set layout to wide # Main UI components st.markdown("