Spaces:
Sleeping
Sleeping
Pierre Lepagnol
commited on
Commit
·
e32fc13
1
Parent(s):
0930db6
App init
Browse files- __init__.py +0 -0
- app.py +5 -0
- requirements.txt +5 -0
- source_code_retriever.py +19 -0
- tool_config.json +5 -0
__init__.py
ADDED
|
File without changes
|
app.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers.tools.base import launch_gradio_demo
|
| 2 |
+
|
| 3 |
+
from source_code_retriever import ScrapperTool
|
| 4 |
+
|
| 5 |
+
launch_gradio_demo(ScrapperTool)
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers>=4.29.0
|
| 2 |
+
diffusers
|
| 3 |
+
accelerate
|
| 4 |
+
torch
|
| 5 |
+
beautifulsoup4
|
source_code_retriever.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
from bs4 import BeautifulSoup
|
| 3 |
+
from transformers import Tool
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class ScrapperTool(Tool):
|
| 7 |
+
name = "source_code_scrapper"
|
| 8 |
+
description = (
|
| 9 |
+
"This is a tool that retrieves the source code of a given webpage. "
|
| 10 |
+
"It takes the URL of the webpage, and returns the source code."
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
inputs = ["text"]
|
| 14 |
+
outputs = ["text"]
|
| 15 |
+
|
| 16 |
+
def __call__(self, url: str):
|
| 17 |
+
response = requests.get(url)
|
| 18 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
| 19 |
+
return soup.prettify()
|
tool_config.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"description": "This is a tool that retrieves the source code of a given webpage. It takes the URL of the webpage, and returns the source code.",
|
| 3 |
+
"name": "source_code_scrapper",
|
| 4 |
+
"tool_class": "source_code_retriever.ScrapperTool"
|
| 5 |
+
}
|