from dotenv import load_dotenv import streamlit as st import os import google.generativeai as genai load_dotenv() genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) # Función para obtener respuesta del modelo Gemini def get_gemini_response(target_audience, product, product_mention, mood, length): model = genai.GenerativeModel("gemini-1.5-flash") # Modelo predeterminado # Crear la instrucción de mención basada en la opción seleccionada mention_instruction = "" if product_mention == "Directa": mention_instruction = f"Mention the product '{product}' directly in the text." elif product_mention == "Indirecta": mention_instruction = f"Ensure that subtle and realistic references to the product '{product}' are included without explicitly mentioning it." elif product_mention == "Metafórica": mention_instruction = f"Refer to the product '{product}' through a metaphor without explicitly mentioning it." # Instrucción específica para el tipo de texto (siempre será "Historia") format_instruction = "Ensure that the narrative is engaging and includes character development, a clear plot, and a resolution." # Crear el prompt completo basado en los campos del frontend full_prompt = f""" You are a creative writer skilled in the art of persuasion. Write a story of {length} words in Spanish. The tone of the story should be {mood} and carefully crafted to emotionally resonate with a {target_audience}. {mention_instruction} {format_instruction} Use persuasive techniques to guide the reader towards an intuitive understanding of the product's benefits, focusing on creating a strong emotional connection with the audience. """ response = model.generate_content([full_prompt]) # Comprobar si la respuesta es válida y devolver el texto if response and response.parts: # Formatear la respuesta en párrafos text = response.parts[0].text paragraphs = text.split("\n") # Suponiendo que los párrafos están separados por saltos de línea formatted_text = "\n\n".join(paragraphs) # Unir los párrafos con dos saltos de línea return formatted_text else: raise ValueError("Lo sentimos, intenta con una combinación diferente de entradas.") # Inicializar la aplicación Streamlit st.set_page_config(page_title="Story Genius Maker", page_icon=":pencil:", layout="wide") # Configurar el diseño en ancho # Título y subtítulo st.markdown("