Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +10 -14
src/streamlit_app.py
CHANGED
|
@@ -16,21 +16,17 @@ def firecrawl_scrape_tool(url: str):
|
|
| 16 |
firecrawl_api_key = os.getenv("FIRECRAWL_API_KEY")
|
| 17 |
if not firecrawl_api_key:
|
| 18 |
return {"error": "Firecrawl API key not found."}
|
| 19 |
-
|
| 20 |
try:
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
)
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
doc = docs[0] if isinstance(docs, list) and docs else docs
|
| 31 |
-
|
| 32 |
-
# Now access attributes directly from the Document object
|
| 33 |
-
return {"content": doc.page_content, "metadata": doc.metadata}
|
| 34 |
|
| 35 |
return {"content": "No content found.", "metadata": {}}
|
| 36 |
except Exception as e:
|
|
|
|
| 16 |
firecrawl_api_key = os.getenv("FIRECRAWL_API_KEY")
|
| 17 |
if not firecrawl_api_key:
|
| 18 |
return {"error": "Firecrawl API key not found."}
|
| 19 |
+
|
| 20 |
try:
|
| 21 |
+
# Create a new instance of the FirecrawlApp for each request to avoid state issues.
|
| 22 |
+
firecrawl_app = FirecrawlApp(api_key=firecrawl_api_key)
|
| 23 |
+
|
| 24 |
+
# Use the updated 'scrape' method
|
| 25 |
+
docs = firecrawl_app.scrape(url=url)
|
| 26 |
+
|
| 27 |
+
# The fix: directly access the attributes from the returned dictionary.
|
| 28 |
+
if docs and isinstance(docs, dict):
|
| 29 |
+
return {"content": docs.get('content'), "metadata": docs.get('metadata')}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
return {"content": "No content found.", "metadata": {}}
|
| 32 |
except Exception as e:
|