Commit
·
0c0e1de
1
Parent(s):
2c2836c
Actualizar el procesamiento del README.md para eliminar la sección de metadatos de Hugging Face y manejar correctamente bloques de código HTML.
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ import os
|
|
11 |
import json
|
12 |
from datetime import datetime
|
13 |
from typing import List, Any
|
|
|
14 |
|
15 |
load_dotenv()
|
16 |
|
@@ -342,7 +343,6 @@ with gr.Blocks(title="OwlBear Agent - Complete History", theme=gr.themes.Default
|
|
342 |
show_api=False
|
343 |
)
|
344 |
|
345 |
-
# Original API interface for backward compatibility
|
346 |
api_demo = gr.Interface(
|
347 |
fn=chat,
|
348 |
inputs=[
|
@@ -355,34 +355,24 @@ api_demo = gr.Interface(
|
|
355 |
|
356 |
with open("README.md", "r", encoding="utf-8") as f:
|
357 |
readme = f.read()
|
358 |
-
# Eliminar la sección de metadatos de Hugging Face si está presente
|
359 |
if readme.startswith("---"):
|
360 |
parts = readme.split("---", 2)
|
361 |
if len(parts) >= 3:
|
362 |
readme = parts[2]
|
363 |
|
364 |
-
# Procesar el README para manejar correctamente bloques de código HTML
|
365 |
-
import re
|
366 |
|
367 |
-
# Encontrar bloques de código HTML (```html ... ```)
|
368 |
html_blocks = re.findall(r'```html\n(.*?)\n```', readme, re.DOTALL)
|
369 |
-
# Reemplazar los bloques de código HTML por marcadores temporales
|
370 |
for i, html_block in enumerate(html_blocks):
|
371 |
readme = readme.replace(f"```html\n{html_block}\n```", f"{{HTML_BLOCK_{i}}}")
|
372 |
|
373 |
-
# Crear un bloque para contener el Markdown y HTML
|
374 |
with gr.Blocks() as intro_demo:
|
375 |
-
# Dividir el contenido por los marcadores de HTML
|
376 |
parts = re.split(r'({HTML_BLOCK_\d+})', readme)
|
377 |
|
378 |
for part in parts:
|
379 |
if part.startswith("{HTML_BLOCK_"):
|
380 |
-
# Extraer el índice del bloque HTML
|
381 |
block_idx = int(part.replace("{HTML_BLOCK_", "").replace("}", ""))
|
382 |
-
# Renderizar el HTML directamente
|
383 |
gr.HTML(html_blocks[block_idx])
|
384 |
else:
|
385 |
-
# Renderizar el contenido Markdown
|
386 |
if part.strip():
|
387 |
gr.Markdown(part)
|
388 |
|
|
|
11 |
import json
|
12 |
from datetime import datetime
|
13 |
from typing import List, Any
|
14 |
+
import re
|
15 |
|
16 |
load_dotenv()
|
17 |
|
|
|
343 |
show_api=False
|
344 |
)
|
345 |
|
|
|
346 |
api_demo = gr.Interface(
|
347 |
fn=chat,
|
348 |
inputs=[
|
|
|
355 |
|
356 |
with open("README.md", "r", encoding="utf-8") as f:
|
357 |
readme = f.read()
|
|
|
358 |
if readme.startswith("---"):
|
359 |
parts = readme.split("---", 2)
|
360 |
if len(parts) >= 3:
|
361 |
readme = parts[2]
|
362 |
|
|
|
|
|
363 |
|
|
|
364 |
html_blocks = re.findall(r'```html\n(.*?)\n```', readme, re.DOTALL)
|
|
|
365 |
for i, html_block in enumerate(html_blocks):
|
366 |
readme = readme.replace(f"```html\n{html_block}\n```", f"{{HTML_BLOCK_{i}}}")
|
367 |
|
|
|
368 |
with gr.Blocks() as intro_demo:
|
|
|
369 |
parts = re.split(r'({HTML_BLOCK_\d+})', readme)
|
370 |
|
371 |
for part in parts:
|
372 |
if part.startswith("{HTML_BLOCK_"):
|
|
|
373 |
block_idx = int(part.replace("{HTML_BLOCK_", "").replace("}", ""))
|
|
|
374 |
gr.HTML(html_blocks[block_idx])
|
375 |
else:
|
|
|
376 |
if part.strip():
|
377 |
gr.Markdown(part)
|
378 |
|