Spaces:
Sleeping
Sleeping
Update firecrawler.py
Browse files- firecrawler.py +23 -23
firecrawler.py
CHANGED
|
@@ -25,31 +25,31 @@ class FireCrawlTool(Tool):
|
|
| 25 |
|
| 26 |
def forward(self, websites_string: str):
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
|
|
|
| 25 |
|
| 26 |
def forward(self, websites_string: str):
|
| 27 |
|
| 28 |
+
# Initialize the FirecrawlApp with the API key
|
| 29 |
+
app = FirecrawlApp(api_key = api_key)
|
| 30 |
|
| 31 |
+
# Convert the websites string to a list
|
| 32 |
+
# Split by commas, newlines, or spaces and strip whitespace
|
| 33 |
+
websites_list = [
|
| 34 |
+
website.strip()
|
| 35 |
+
for website in websites_string.replace(',', ' ').replace('\n', ' ').split()
|
| 36 |
+
if website.strip()
|
| 37 |
+
]
|
| 38 |
|
| 39 |
+
# Define the extraction schema
|
| 40 |
+
class ExtractSchema(BaseModel):
|
| 41 |
+
company_name: str
|
| 42 |
+
website_purpose: str
|
| 43 |
|
| 44 |
+
prompt_string = 'Extract the website purpose and company name.'
|
| 45 |
|
| 46 |
+
# Execute the API call
|
| 47 |
+
data = app.extract(
|
| 48 |
+
websites_list,
|
| 49 |
+
{
|
| 50 |
+
'prompt': prompt_string,
|
| 51 |
+
'schema': ExtractSchema.model_json_schema(),
|
| 52 |
+
}
|
| 53 |
+
)
|
| 54 |
|
| 55 |
+
return data
|