Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -24,32 +24,29 @@ model = HfApiModel(
|
|
24 |
@tool
|
25 |
def save_scraped_data_as_markdown(scraped_data: dict, filename: str = None) -> str:
|
26 |
"""
|
27 |
-
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
Retorna:
|
36 |
-
str: Mensaje indicando si el archivo fue guardado correctamente o si ocurrió un error.
|
37 |
"""
|
38 |
try:
|
39 |
-
url = scraped_data.get("url", "
|
40 |
content_list = scraped_data.get("scraped_data", [])
|
41 |
|
42 |
if not content_list:
|
43 |
-
return "No
|
44 |
|
45 |
formatted_content = "\n\n".join(content_list)
|
46 |
|
47 |
-
#
|
48 |
-
markdown_content = f"#
|
49 |
-
markdown_content += "##
|
50 |
markdown_content += formatted_content
|
51 |
|
52 |
-
#
|
53 |
if not filename:
|
54 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
55 |
filename = f"scraped_{timestamp}.md"
|
@@ -57,10 +54,11 @@ def save_scraped_data_as_markdown(scraped_data: dict, filename: str = None) -> s
|
|
57 |
with open(filename, "w", encoding="utf-8") as file:
|
58 |
file.write(markdown_content)
|
59 |
|
60 |
-
return f"
|
61 |
|
62 |
except Exception as e:
|
63 |
-
return f"Error
|
|
|
64 |
|
65 |
|
66 |
|
|
|
24 |
@tool
|
25 |
def save_scraped_data_as_markdown(scraped_data: dict, filename: str = None) -> str:
|
26 |
"""
|
27 |
+
Save scraped content as a well-formatted Markdown file.
|
28 |
|
29 |
+
:param scraped_data: A dictionary containing:
|
30 |
+
- url (str): The URL of the webpage from which the content was scraped.
|
31 |
+
- scraped_data (list[str]): A list of text fragments extracted from the webpage.
|
32 |
+
:param filename: (Optional) The name of the output Markdown file. If not provided, a filename is generated using a timestamp.
|
33 |
+
:return: A string message indicating whether the file was saved successfully or an error occurred.
|
|
|
|
|
|
|
34 |
"""
|
35 |
try:
|
36 |
+
url = scraped_data.get("url", "Unknown")
|
37 |
content_list = scraped_data.get("scraped_data", [])
|
38 |
|
39 |
if not content_list:
|
40 |
+
return "No data available to save in Markdown."
|
41 |
|
42 |
formatted_content = "\n\n".join(content_list)
|
43 |
|
44 |
+
# Build Markdown content
|
45 |
+
markdown_content = f"# Content extracted from {url}\n\n"
|
46 |
+
markdown_content += "## Full Content\n\n"
|
47 |
markdown_content += formatted_content
|
48 |
|
49 |
+
# Generate a filename with a timestamp if not provided
|
50 |
if not filename:
|
51 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
52 |
filename = f"scraped_{timestamp}.md"
|
|
|
54 |
with open(filename, "w", encoding="utf-8") as file:
|
55 |
file.write(markdown_content)
|
56 |
|
57 |
+
return f"Scraped content has been saved in {filename}"
|
58 |
|
59 |
except Exception as e:
|
60 |
+
return f"Error generating Markdown file: {str(e)}"
|
61 |
+
|
62 |
|
63 |
|
64 |
|