File size: 8,136 Bytes
ed0e4b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1048e48
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
import streamlit as st

def apply_styles():
    return """
        <style>
        /* Remove top margin and reduce other margins */
        .main .block-container {
            padding-top: 1rem !important;
            margin-top: 0 !important;
            max-width: 95% !important;
        }
        
        h1, h3 {
            text-align: center;
            margin-top: 0.5rem !important;
            margin-bottom: 0.5rem !important;
        }
        
        .stButton > button {
            background-color: #FFD700 !important;
            color: black !important;
            border: 1px solid black !important;
            font-weight: bold !important;
            width: 80% !important;
            margin-left: 10% !important;
        }
        
        [data-testid="stDownloadButton"] {
            text-align: center;
            display: flex;
            justify-content: center;
            margin-top: 5px;
            width: 90%;
            margin-left: auto;
            margin-right: auto;
        }
        
        [data-testid="stDownloadButton"] button {
            width: 100%;
            border-radius: 5px;
            height: 3em;
            background: linear-gradient(to right, #00D100, #009900);
            color: white;
            font-weight: bold;
            transition: all 0.3s ease;
            border: none;
            text-transform: uppercase;
            letter-spacing: 1px;
        }
        
        [data-testid="stDownloadButton"] button:hover {
            background: linear-gradient(to right, #00C000, #008800);
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }
        
        .stButton > button:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
            transition: all 0.3s ease;
        }
        
        /* Hide the hamburger menu and Streamlit footer */
        #MainMenu {visibility: hidden;}
        footer {visibility: hidden;}
        
        /* Creative Concept Styling */
        .concept-title {
            font-size: 1.5rem;
            font-weight: bold;
            color: #2c3e50;
            margin-top: 2rem;
            padding: 0.5rem;
            border-bottom: 2px solid #3498db;
        }
        
        .section-header {
            font-size: 1.2rem;
            font-weight: bold;
            color: #3498db;
            margin-top: 1rem;
            margin-bottom: 0.5rem;
        }
        
        .analogy {
            color: #e74c3c;
            font-weight: bold;
        }
        
        .creative-concepts {
            background-color: #f8f9fa;
            padding: 1.5rem;
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
            margin-bottom: 1.5rem;
        }
        </style>
    """
    st.markdown("""
        <style>
        .stTextArea > label {
            font-size: 1.2rem;
            font-weight: bold;
            color: #2c3e50;
        }
        
        .stSelectbox > label {
            font-size: 1.2rem;
            font-weight: bold;
            color: #2c3e50;
        }
        
        .stSlider > label {
            font-size: 1.2rem;
            font-weight: bold;
            color: #2c3e50;
        }
        
        .stButton > button {
            background-color: #2c3e50;
            color: white;
            padding: 0.5rem 2rem;
            font-size: 1.1rem;
            font-weight: bold;
            border-radius: 5px;
        }
        
        .stButton > button:hover {
            background-color: #34495e;
        }
        
        h1 {
            color: #2c3e50;
            font-size: 2.5rem;
            margin-bottom: 1rem;
        }
        
        h3 {
            color: #34495e;
            font-size: 1.3rem;
            font-weight: normal;
            margin-bottom: 2rem;
        }
        
        .stMarkdown {
            font-size: 1.1rem;
        }
        
        .element-container {
            margin-bottom: 1rem;
        }
        </style>
    """, 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'<div class="creative-concept-card">'
        html += f'<div class="concept-title">{concept["title"]}</div>'
        
        for item in concept["content"]:
            html += f'<div class="concept-section">'
            html += f'<div class="section-header">{item["header"]}</div>'
            
            # 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'<span class="analogy">\1</span>', item["text"])
                html += f'<div class="section-content">{styled_text}</div>'
            else:
                html += f'<div class="section-content">{item["text"]}</div>'
            
            html += '</div>'
        
        html += '</div>'
    
    # Add custom CSS for the new layout
    css = """
    <style>
    .creative-concept-card {
        background-color: #f8f9fa;
        padding: 1.5rem;
        border-radius: 10px;
        box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        margin-bottom: 2rem;
        margin-top: 0.5rem;  /* Reduced top margin */
    }
    
    .concept-title {
        font-size: 1.5rem;
        font-weight: bold;
        color: #2c3e50;
        padding-bottom: 0.5rem;
        border-bottom: 2px solid #3498db;
        margin-bottom: 1.5rem;
        margin-top: 0;  /* Remove top margin from title */
    }
    
    /* Additional style to reduce space at the top of the output area */
    .stMarkdown {
        margin-top: 0 !important;
        padding-top: 0 !important;
    }
    
    /* Ensure the first concept has minimal top margin */
    .creative-concept-card:first-child {
        margin-top: 0;
    }
    
    .concept-section {
        margin-bottom: 1.5rem;
    }
    
    .section-header {
        font-size: 1.2rem;
        font-weight: bold;
        color: #3498db;
        margin-bottom: 0.5rem;
    }
    
    .section-content {
        font-size: 1.1rem;
        line-height: 1.5;
    }
    
    .analogy {
        color: #e74c3c;
        font-weight: bold;
    }
    </style>
    """
    
    return css + html

def format_story_output(story_text):
    return f"""
        <div class="story-output">
            {story_text}
        </div>
    """