Spaces:
Sleeping
Sleeping
Update styles.py
Browse files
styles.py
CHANGED
|
@@ -157,27 +157,106 @@ def format_creative_response(response_text):
|
|
| 157 |
if not response_text or response_text.startswith("Error") or response_text.startswith("Debes"):
|
| 158 |
return response_text
|
| 159 |
|
| 160 |
-
#
|
| 161 |
-
|
|
|
|
|
|
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
-
# Add
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
formatted_response = formatted_response.replace("<br>Ejemplo de Titular:", "<br><div class='section-header'>Ejemplo de Titular:</div>")
|
| 171 |
|
| 172 |
-
#
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
-
|
| 178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
-
return
|
| 181 |
|
| 182 |
def format_story_output(story_text):
|
| 183 |
return f"""
|
|
|
|
| 157 |
if not response_text or response_text.startswith("Error") or response_text.startswith("Debes"):
|
| 158 |
return response_text
|
| 159 |
|
| 160 |
+
# Parse the response into sections
|
| 161 |
+
sections = []
|
| 162 |
+
current_concept = {"title": "", "content": []}
|
| 163 |
+
current_section = None
|
| 164 |
|
| 165 |
+
for line in response_text.split('\n'):
|
| 166 |
+
line = line.strip()
|
| 167 |
+
if not line:
|
| 168 |
+
continue
|
| 169 |
+
|
| 170 |
+
if line.startswith("CONCEPTO CREATIVO"):
|
| 171 |
+
# Start a new concept
|
| 172 |
+
if current_concept["title"]:
|
| 173 |
+
sections.append(current_concept)
|
| 174 |
+
current_concept = {"title": line, "content": []}
|
| 175 |
+
current_section = None
|
| 176 |
+
elif line.startswith("Concepto:"):
|
| 177 |
+
current_section = "concept"
|
| 178 |
+
current_concept["content"].append({"type": current_section, "header": line, "text": ""})
|
| 179 |
+
elif line.startswith("Creatividad:"):
|
| 180 |
+
current_section = "creativity"
|
| 181 |
+
current_concept["content"].append({"type": current_section, "header": line, "text": ""})
|
| 182 |
+
elif line.startswith("Ejemplo de Titular:"):
|
| 183 |
+
current_section = "headline"
|
| 184 |
+
current_concept["content"].append({"type": current_section, "header": line, "text": ""})
|
| 185 |
+
elif current_section:
|
| 186 |
+
# Add content to the current section
|
| 187 |
+
current_concept["content"][-1]["text"] = line
|
| 188 |
|
| 189 |
+
# Add the last concept
|
| 190 |
+
if current_concept["title"]:
|
| 191 |
+
sections.append(current_concept)
|
|
|
|
| 192 |
|
| 193 |
+
# Build the HTML
|
| 194 |
+
html = ""
|
| 195 |
+
for concept in sections:
|
| 196 |
+
html += f'<div class="creative-concept-card">'
|
| 197 |
+
html += f'<div class="concept-title">{concept["title"]}</div>'
|
| 198 |
+
|
| 199 |
+
for item in concept["content"]:
|
| 200 |
+
html += f'<div class="concept-section">'
|
| 201 |
+
html += f'<div class="section-header">{item["header"]}</div>'
|
| 202 |
+
|
| 203 |
+
# Apply special styling to analogy text
|
| 204 |
+
if item["type"] == "creativity" and "es como" in item["text"] and "porque" in item["text"]:
|
| 205 |
+
import re
|
| 206 |
+
analogy_pattern = r'([^\.]+es como [^\.]+porque [^\.]+)'
|
| 207 |
+
styled_text = re.sub(analogy_pattern, r'<span class="analogy">\1</span>', item["text"])
|
| 208 |
+
html += f'<div class="section-content">{styled_text}</div>'
|
| 209 |
+
else:
|
| 210 |
+
html += f'<div class="section-content">{item["text"]}</div>'
|
| 211 |
+
|
| 212 |
+
html += '</div>'
|
| 213 |
+
|
| 214 |
+
html += '</div>'
|
| 215 |
+
|
| 216 |
+
# Add custom CSS for the new layout
|
| 217 |
+
css = """
|
| 218 |
+
<style>
|
| 219 |
+
.creative-concept-card {
|
| 220 |
+
background-color: #f8f9fa;
|
| 221 |
+
padding: 1.5rem;
|
| 222 |
+
border-radius: 10px;
|
| 223 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
| 224 |
+
margin-bottom: 2rem;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
.concept-title {
|
| 228 |
+
font-size: 1.5rem;
|
| 229 |
+
font-weight: bold;
|
| 230 |
+
color: #2c3e50;
|
| 231 |
+
padding-bottom: 0.5rem;
|
| 232 |
+
border-bottom: 2px solid #3498db;
|
| 233 |
+
margin-bottom: 1.5rem;
|
| 234 |
+
}
|
| 235 |
|
| 236 |
+
.concept-section {
|
| 237 |
+
margin-bottom: 1.5rem;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
.section-header {
|
| 241 |
+
font-size: 1.2rem;
|
| 242 |
+
font-weight: bold;
|
| 243 |
+
color: #3498db;
|
| 244 |
+
margin-bottom: 0.5rem;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
.section-content {
|
| 248 |
+
font-size: 1.1rem;
|
| 249 |
+
line-height: 1.5;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
.analogy {
|
| 253 |
+
color: #e74c3c;
|
| 254 |
+
font-weight: bold;
|
| 255 |
+
}
|
| 256 |
+
</style>
|
| 257 |
+
"""
|
| 258 |
|
| 259 |
+
return css + html
|
| 260 |
|
| 261 |
def format_story_output(story_text):
|
| 262 |
return f"""
|