Spaces:
Runtime error
Runtime error
Abhay Mishra
commited on
Commit
·
82b2152
1
Parent(s):
98b9da9
initial commit
Browse files- app.py +37 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.system("pip install git+https://github.com/openai/whisper.git")
|
3 |
+
import whisper
|
4 |
+
|
5 |
+
from pytube import YouTube
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
infer_model = whisper.load_model("base")
|
9 |
+
|
10 |
+
def infer(link):
|
11 |
+
audio_path = download_audio(link)
|
12 |
+
if audio_path is None:
|
13 |
+
return "Unable to process request."
|
14 |
+
|
15 |
+
result = infer_model.transcribe(audio_path)
|
16 |
+
print(result["text"])
|
17 |
+
return result["text"]
|
18 |
+
|
19 |
+
def download_audio(link):
|
20 |
+
try:
|
21 |
+
yt = YouTube(link)
|
22 |
+
stream = yt.streams.get_audio_only()
|
23 |
+
audio_path = stream.download()
|
24 |
+
print(audio_path)
|
25 |
+
return audio_path
|
26 |
+
except Exception as e:
|
27 |
+
print(f"Unable to download file. Exception {e}")
|
28 |
+
return None
|
29 |
+
|
30 |
+
|
31 |
+
demo = gr.Interface(
|
32 |
+
fn=infer,
|
33 |
+
inputs= "text",
|
34 |
+
outputs= "text"
|
35 |
+
)
|
36 |
+
|
37 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
pytube
|