Spaces:
Runtime error
Runtime error
Commit
·
c66cdec
1
Parent(s):
97fed4a
🚧 transcribe_audio_with_whisper
Browse files- app.py +2 -0
- requirements.txt +2 -0
- tools.py +34 -0
app.py
CHANGED
|
@@ -17,6 +17,7 @@ from tools import (
|
|
| 17 |
count_tables_in_wikipedia_section,
|
| 18 |
extract_nth_table_in_wikipedia_section,
|
| 19 |
wikipedia_featured_articles_title,
|
|
|
|
| 20 |
)
|
| 21 |
|
| 22 |
# (Keep Constants as is)
|
|
@@ -74,6 +75,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 74 |
count_tables_in_wikipedia_section,
|
| 75 |
extract_nth_table_in_wikipedia_section,
|
| 76 |
wikipedia_featured_articles_title,
|
|
|
|
| 77 |
],
|
| 78 |
verbosity_level=2,
|
| 79 |
additional_authorized_imports=authorized_imports,
|
|
|
|
| 17 |
count_tables_in_wikipedia_section,
|
| 18 |
extract_nth_table_in_wikipedia_section,
|
| 19 |
wikipedia_featured_articles_title,
|
| 20 |
+
transcribe_audio_with_whisper,
|
| 21 |
)
|
| 22 |
|
| 23 |
# (Keep Constants as is)
|
|
|
|
| 75 |
count_tables_in_wikipedia_section,
|
| 76 |
extract_nth_table_in_wikipedia_section,
|
| 77 |
wikipedia_featured_articles_title,
|
| 78 |
+
transcribe_audio_with_whisper,
|
| 79 |
],
|
| 80 |
verbosity_level=2,
|
| 81 |
additional_authorized_imports=authorized_imports,
|
requirements.txt
CHANGED
|
@@ -2,4 +2,6 @@ gradio
|
|
| 2 |
pandas
|
| 3 |
requests
|
| 4 |
smolagents[toolkit]
|
|
|
|
|
|
|
| 5 |
wikipedia-api
|
|
|
|
| 2 |
pandas
|
| 3 |
requests
|
| 4 |
smolagents[toolkit]
|
| 5 |
+
torch
|
| 6 |
+
transformers
|
| 7 |
wikipedia-api
|
tools.py
CHANGED
|
@@ -2,6 +2,9 @@ from bs4 import BeautifulSoup
|
|
| 2 |
import requests
|
| 3 |
import re
|
| 4 |
from smolagents import tool
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
@tool
|
|
@@ -177,3 +180,34 @@ def wikipedia_featured_articles_title(year: int) -> str:
|
|
| 177 |
"Wikipedia:Featured articles promoted in 2021".
|
| 178 |
"""
|
| 179 |
return f"Wikipedia:Featured articles promoted in {year}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import requests
|
| 3 |
import re
|
| 4 |
from smolagents import tool
|
| 5 |
+
import torch
|
| 6 |
+
import spaces
|
| 7 |
+
from transformers import pipeline
|
| 8 |
|
| 9 |
|
| 10 |
@tool
|
|
|
|
| 180 |
"Wikipedia:Featured articles promoted in 2021".
|
| 181 |
"""
|
| 182 |
return f"Wikipedia:Featured articles promoted in {year}"
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
device = (
|
| 186 |
+
torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
| 187 |
+
)
|
| 188 |
+
|
| 189 |
+
asr_pipeline = pipeline(
|
| 190 |
+
"automatic-speech-recognition",
|
| 191 |
+
model="openai/whisper-large-v3",
|
| 192 |
+
device=device,
|
| 193 |
+
chunk_length_s=30,
|
| 194 |
+
return_timestamps=False,
|
| 195 |
+
generate_kwargs={"task": "transcribe"},
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
@tool
|
| 200 |
+
@spaces.GPU
|
| 201 |
+
def transcribe_audio_with_whisper(filename: str) -> str:
|
| 202 |
+
"""
|
| 203 |
+
Transcribe an audio file into text using Whisper.
|
| 204 |
+
|
| 205 |
+
Args:
|
| 206 |
+
filename (str): Path to the audio file on disk (e.g., "input/Strawberry pie.mp3").
|
| 207 |
+
|
| 208 |
+
Returns:
|
| 209 |
+
str: Transcribed text of the audio content.
|
| 210 |
+
"""
|
| 211 |
+
with open(filename, "rb") as f:
|
| 212 |
+
audio_bytes = f.read()
|
| 213 |
+
return asr_pipeline(audio_bytes)["text"]
|