Upload tool
Browse files- app.py +7 -0
- requirements.txt +2 -0
- tool.py +26 -0
app.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import launch_gradio_demo
|
| 2 |
+
from typing import Optional
|
| 3 |
+
from tool import VisitWebpageMDTool
|
| 4 |
+
|
| 5 |
+
tool = VisitWebpageMDTool()
|
| 6 |
+
|
| 7 |
+
launch_gradio_demo(tool)
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
requests
|
| 2 |
+
smolagents
|
tool.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents.tools import Tool
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
class VisitWebpageMDTool(Tool):
|
| 5 |
+
name = "visit_webpage_markdown"
|
| 6 |
+
description = "Visits a webpage at the given url and reads its content as a markdown document via Jina. Use this to browse webpages. It skips images / medias"
|
| 7 |
+
inputs = {'url': {'type': 'string', 'description': 'The url of the webpage to visit.'}}
|
| 8 |
+
output_type = "string"
|
| 9 |
+
|
| 10 |
+
def forward(self, url: str) -> str:
|
| 11 |
+
import requests
|
| 12 |
+
try:
|
| 13 |
+
# Send a GET request to the URL
|
| 14 |
+
response = requests.get('https://r.jina.ai/' +url)
|
| 15 |
+
response.raise_for_status() # Raise an exception for bad status codes
|
| 16 |
+
|
| 17 |
+
markdown_content =response.text.strip()
|
| 18 |
+
return markdown_content
|
| 19 |
+
|
| 20 |
+
except Exception as e:
|
| 21 |
+
return f"An unexpected error occurred: {str(e)}"
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def __init__(self, *args, **kwargs):
|
| 25 |
+
self.is_initialized = False
|
| 26 |
+
|