import streamlit as st def apply_styles(): return """ """ st.markdown(""" """, unsafe_allow_html=True) def format_creative_response(response_text): """Format the creative response with custom styling""" if not response_text or response_text.startswith("Error") or response_text.startswith("Debes"): return response_text # Parse the response into sections sections = [] current_concept = {"title": "", "content": []} current_section = None for line in response_text.split('\n'): line = line.strip() if not line: continue if line.startswith("CONCEPTO CREATIVO"): # Start a new concept if current_concept["title"]: sections.append(current_concept) current_concept = {"title": line, "content": []} current_section = None elif line.startswith("Concepto:"): current_section = "concept" current_concept["content"].append({"type": current_section, "header": line, "text": ""}) elif line.startswith("Creatividad:"): current_section = "creativity" current_concept["content"].append({"type": current_section, "header": line, "text": ""}) elif line.startswith("Ejemplo de Titular:"): current_section = "headline" current_concept["content"].append({"type": current_section, "header": line, "text": ""}) elif current_section: # Add content to the current section current_concept["content"][-1]["text"] = line # Add the last concept if current_concept["title"]: sections.append(current_concept) # Build the HTML html = "" for concept in sections: html += f'
' html += f'
{concept["title"]}
' for item in concept["content"]: html += f'
' html += f'
{item["header"]}
' # Apply special styling to analogy text if item["type"] == "creativity" and "es como" in item["text"] and "porque" in item["text"]: import re analogy_pattern = r'([^\.]+es como [^\.]+porque [^\.]+)' styled_text = re.sub(analogy_pattern, r'\1', item["text"]) html += f'
{styled_text}
' else: html += f'
{item["text"]}
' html += '
' html += '
' # Add custom CSS for the new layout css = """ """ return css + html def format_story_output(story_text): return f"""
{story_text}
"""