Spaces:
Sleeping
Sleeping
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 HFSpeech2TextFromFile
|
4 |
+
|
5 |
+
tool = HFSpeech2TextFromFile()
|
6 |
+
|
7 |
+
launch_gradio_demo(tool)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
smolagents
|
2 |
+
requests
|
tool.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from smolagents.tools import Tool
|
2 |
+
import requests
|
3 |
+
|
4 |
+
class HFSpeech2TextFromFile(Tool):
|
5 |
+
name = "HFSpeech2TextFromFile"
|
6 |
+
description = "This is a tool that returns text transcription from an audio file path, calling huggingface-api under the hood."
|
7 |
+
inputs = {'filepath': {'type': 'string', 'description': 'Path to audio file'}, 'hf_token': {'type': 'string', 'description': 'your huggingface token to call huggingface api'}, 'model': {'type': 'string', 'description': "optional, the model to call. Optional. Defaults to 'whisper-small.en'", 'nullable': True}}
|
8 |
+
output_type = "string"
|
9 |
+
|
10 |
+
def forward(self, filepath: str, hf_token: str, \
|
11 |
+
model: str = "whisper-small.en") -> str:
|
12 |
+
import requests
|
13 |
+
|
14 |
+
with open(filepath, "rb") as f:
|
15 |
+
data = f.read()
|
16 |
+
|
17 |
+
response = requests.post(
|
18 |
+
f"https://api-inference.huggingface.co/models/openai/{model}",
|
19 |
+
headers={"Authorization": f"Bearer {hf_token}"},
|
20 |
+
data=data
|
21 |
+
)
|
22 |
+
|
23 |
+
return response.json()['text']
|
24 |
+
|
25 |
+
def __init__(self, *args, **kwargs):
|
26 |
+
self.is_initialized = False
|