Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,47 +21,6 @@ model = HfApiModel(
|
|
| 21 |
custom_role_conversions=None,
|
| 22 |
)
|
| 23 |
|
| 24 |
-
@tool
|
| 25 |
-
def save_scraped_data_as_markdown(scraped_data: dict, filename: str = None) -> str:
|
| 26 |
-
"""
|
| 27 |
-
Guarda el contenido scrapeado en un archivo Markdown bien formateado.
|
| 28 |
-
|
| 29 |
-
Args:
|
| 30 |
-
scraped_data (dict): Diccionario que contiene:
|
| 31 |
-
- 'url' (str): La URL de la página de la cual se extrajo el contenido.
|
| 32 |
-
- 'scraped_data' (list[str]): Lista de fragmentos de texto extraídos.
|
| 33 |
-
filename (str, optional): Nombre del archivo Markdown de salida. Si no se proporciona, se genera uno usando la fecha y hora actual.
|
| 34 |
-
|
| 35 |
-
Returns:
|
| 36 |
-
str: Mensaje indicando si el archivo se guardó correctamente o si ocurrió algún error.
|
| 37 |
-
"""
|
| 38 |
-
try:
|
| 39 |
-
url = scraped_data.get("url", "Unknown")
|
| 40 |
-
content_list = scraped_data.get("scraped_data", [])
|
| 41 |
-
|
| 42 |
-
if not content_list:
|
| 43 |
-
return "No data available to save in Markdown."
|
| 44 |
-
|
| 45 |
-
formatted_content = "\n\n".join(content_list)
|
| 46 |
-
|
| 47 |
-
# Construir el contenido Markdown
|
| 48 |
-
markdown_content = f"# Content extracted from {url}\n\n"
|
| 49 |
-
markdown_content += "## Full Content\n\n"
|
| 50 |
-
markdown_content += formatted_content
|
| 51 |
-
|
| 52 |
-
# Generar un nombre de archivo con timestamp si no se proporciona
|
| 53 |
-
if not filename:
|
| 54 |
-
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 55 |
-
filename = f"scraped_{timestamp}.md"
|
| 56 |
-
|
| 57 |
-
with open(filename, "w", encoding="utf-8") as file:
|
| 58 |
-
file.write(markdown_content)
|
| 59 |
-
|
| 60 |
-
return f"Scraped content has been saved in {filename}"
|
| 61 |
-
|
| 62 |
-
except Exception as e:
|
| 63 |
-
return f"Error generating Markdown file: {str(e)}"
|
| 64 |
-
|
| 65 |
@tool
|
| 66 |
|
| 67 |
def summarize_text(text):
|
|
@@ -144,6 +103,47 @@ def extract_metadata_from_url(url: str) -> dict:
|
|
| 144 |
except requests.exceptions.RequestException as e:
|
| 145 |
return {"error": f"Error al acceder a la URL: {str(e)}"}
|
| 146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
@tool
|
| 149 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 21 |
custom_role_conversions=None,
|
| 22 |
)
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
@tool
|
| 25 |
|
| 26 |
def summarize_text(text):
|
|
|
|
| 103 |
except requests.exceptions.RequestException as e:
|
| 104 |
return {"error": f"Error al acceder a la URL: {str(e)}"}
|
| 105 |
|
| 106 |
+
@tool
|
| 107 |
+
def save_scraped_data_as_markdown(scraped_data: dict, filename: str = None) -> str:
|
| 108 |
+
"""
|
| 109 |
+
Guarda el contenido scrapeado en un archivo Markdown bien formateado.
|
| 110 |
+
|
| 111 |
+
Args:
|
| 112 |
+
scraped_data (dict): Diccionario que contiene:
|
| 113 |
+
- 'url' (str): La URL de la página de la cual se extrajo el contenido.
|
| 114 |
+
- 'scraped_data' (list[str]): Lista de fragmentos de texto extraídos.
|
| 115 |
+
filename (str, optional): Nombre del archivo Markdown de salida. Si no se proporciona, se genera uno usando la fecha y hora actual.
|
| 116 |
+
|
| 117 |
+
Returns:
|
| 118 |
+
str: Mensaje indicando si el archivo se guardó correctamente o si ocurrió algún error.
|
| 119 |
+
"""
|
| 120 |
+
try:
|
| 121 |
+
url = scraped_data.get("url", "Unknown")
|
| 122 |
+
content_list = scraped_data.get("scraped_data", [])
|
| 123 |
+
|
| 124 |
+
if not content_list:
|
| 125 |
+
return "No data available to save in Markdown."
|
| 126 |
+
|
| 127 |
+
formatted_content = "\n\n".join(content_list)
|
| 128 |
+
|
| 129 |
+
# Construir el contenido Markdown
|
| 130 |
+
markdown_content = f"# Content extracted from {url}\n\n"
|
| 131 |
+
markdown_content += "## Full Content\n\n"
|
| 132 |
+
markdown_content += formatted_content
|
| 133 |
+
|
| 134 |
+
# Generar un nombre de archivo con timestamp si no se proporciona
|
| 135 |
+
if not filename:
|
| 136 |
+
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 137 |
+
filename = f"scraped_{timestamp}.md"
|
| 138 |
+
|
| 139 |
+
with open(filename, "w", encoding="utf-8") as file:
|
| 140 |
+
file.write(markdown_content)
|
| 141 |
+
|
| 142 |
+
return f"Scraped content has been saved in {filename}"
|
| 143 |
+
|
| 144 |
+
except Exception as e:
|
| 145 |
+
return f"Error generating Markdown file: {str(e)}"
|
| 146 |
+
|
| 147 |
|
| 148 |
@tool
|
| 149 |
def get_current_time_in_timezone(timezone: str) -> str:
|