Rehan12345678 commited on
Commit
65bbd88
·
verified ·
1 Parent(s): 6e01310

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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
- loader = FireCrawlLoader(
22
- url=url,
23
- api_key=firecrawl_api_key,
24
- mode="scrape"
25
- )
26
- docs = loader.load()
27
- if docs:
28
- # The fix is here: check if the object is a list or a single object.
29
- # If it's a list, get the first item. Otherwise, use the object directly.
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: