Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import sys | |
| import os | |
| # Add the project root to Python path | |
| sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) | |
| from src.services.story_generator import StoryGenerator | |
| from src.data.story_formulas import story_formulas | |
| def render_story_form(): | |
| st.markdown("<h1 style='text-align: center;'>Story Genius Maker</h1>", unsafe_allow_html=True) | |
| st.markdown("<h3 style='text-align: center;'>Teje historias inolvidables en segundos, guiado por la magia de la inteligencia artificial que da vida a tus ideas en relatos cautivadores.</h3>", unsafe_allow_html=True) | |
| col1, col2 = st.columns([2, 3]) | |
| with col1: | |
| target_audience = st.text_input("Público objetivo", placeholder="¿A quién está dirigido tu mensaje?") | |
| product = st.text_input("Producto/Servicio", placeholder="¿Qué estás ofreciendo?") | |
| action = st.text_area("Llamado a la acción", placeholder="¿Qué acción específica debe tomar tu audiencia?") | |
| with st.expander("Personaliza tu historia"): | |
| available_formulas = list(story_formulas.keys()) | |
| formula_display_names = [] | |
| formula_mapping = {} | |
| for formula in available_formulas: | |
| display_name = '.'.join(list(formula)) if formula.isupper() else formula | |
| formula_display_names.append(display_name) | |
| formula_mapping[display_name] = formula | |
| formula = st.radio("Selecciona la fórmula para generar tu historia:", formula_display_names) | |
| selected_formula = formula_mapping[formula] | |
| mood = st.selectbox("Tono de la historia:", ["Emocional", "Triste", "Feliz", "Horror", "Comedia", "Romántico"]) | |
| length = st.slider("Longitud de la historia (palabras):", min_value=50, max_value=150, value=100, step=10) | |
| temperature = st.slider("Nivel de creatividad:", min_value=0.0, max_value=2.0, value=1.0, step=0.1) | |
| story_topic = None | |
| if selected_formula == "GHA": | |
| story_topic = st.text_area("De qué quieres que trate la historia", | |
| placeholder="Explica si hay algo específico sobre lo que te gustaría contar.") | |
| submit = st.button("Generar mi historia") | |
| with col2: | |
| if submit: | |
| if target_audience and product and action: | |
| try: | |
| story_generator = StoryGenerator() | |
| if selected_formula == "GHA" and not story_topic: | |
| st.error("Por favor, completa todos los campos requeridos para la fórmula G.H.A.") | |
| else: | |
| response = story_generator.generate_story( | |
| selected_formula, target_audience, product, | |
| action, mood, length, temperature, story_topic | |
| ) | |
| if response: | |
| st.markdown(f""" | |
| <div class="story-container"> | |
| <h3 class="story-title">Historia Generada:</h3> | |
| <p class="story-content">{response}</p> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| except ValueError as e: | |
| st.error(f"Error: {str(e)}") | |
| else: | |
| st.error("Por favor, completa todos los campos requeridos.") |