Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,60 +1,47 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
import os
|
3 |
-
import requests
|
4 |
from gradio_client import Client
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
16 |
client = Client("https://sanchit-gandhi-whisper-jax.hf.space/")
|
17 |
-
result =
|
18 |
-
|
19 |
-
# If the "summarize" checkbox is selected, summarize the transcription
|
20 |
-
if summarize:
|
21 |
-
transcription = result[1]
|
22 |
-
summary_result = query({"inputs": transcription})
|
23 |
-
try:
|
24 |
-
result[2] = summary_result[0]['summary_text']
|
25 |
-
except:
|
26 |
-
result[2] = 'Model is overloaded.'
|
27 |
-
|
28 |
-
else:
|
29 |
-
result[2] = ''
|
30 |
-
|
31 |
return result
|
32 |
|
|
|
|
|
33 |
MODEL_NAME = "openai/whisper-large-v2"
|
34 |
|
|
|
35 |
demo = gr.Blocks()
|
36 |
|
37 |
EXAMPLES = [
|
38 |
-
["https://www.youtube.com/watch?v=
|
39 |
]
|
40 |
|
41 |
-
|
42 |
yt_transcribe = gr.Interface(
|
43 |
-
fn=
|
44 |
inputs=[
|
45 |
gr.inputs.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL"),
|
46 |
gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
|
47 |
-
gr.inputs.Checkbox(label="Return timestamps")
|
48 |
-
gr.inputs.Checkbox(label="Summarize") # Added "Summarize" checkbox
|
49 |
-
],
|
50 |
-
outputs=[
|
51 |
-
gr.outputs.HTML(label="Video"),
|
52 |
-
gr.outputs.Textbox(label="Transcription").style(show_copy_button=True),
|
53 |
-
gr.outputs.Textbox(label="Summary").style(show_copy_button=True) # Added "Summary" output
|
54 |
],
|
|
|
|
|
55 |
layout="horizontal",
|
56 |
theme=gr.themes.Base(),
|
57 |
-
title="Whisper Large V2: Transcribe YouTube
|
58 |
description=(
|
59 |
"Transcribe long-form YouTube videos with the click of a button! Demo uses the checkpoint"
|
60 |
f" [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe video files of"
|
@@ -65,8 +52,8 @@ yt_transcribe = gr.Interface(
|
|
65 |
cache_examples=False
|
66 |
)
|
67 |
|
68 |
-
with demo
|
69 |
gr.DuplicateButton()
|
70 |
-
gr.TabbedInterface([yt_transcribe], ["YouTube"])
|
71 |
|
72 |
-
demo.launch(enable_queue=True)
|
|
|
1 |
import gradio as gr
|
2 |
+
|
3 |
import os
|
|
|
4 |
from gradio_client import Client
|
5 |
|
6 |
+
def transcribe_audio(youtube_url: str, task: str = "transcribe", return_timestamps: bool = False, api_name: str = "/predict_2") -> dict:
|
7 |
+
"""
|
8 |
+
Transcribe audio from a given YouTube URL using a specified model.
|
9 |
+
Parameters:
|
10 |
+
- youtube_url (str): The YouTube URL to transcribe.
|
11 |
+
- task (str, optional): The task to perform. Default is "transcribe".
|
12 |
+
- return_timestamps (bool, optional): Whether to return timestamps. Default is True.
|
13 |
+
- api_name (str, optional): The API endpoint to use. Default is "/predict_2".
|
14 |
+
Returns:
|
15 |
+
- dict: The transcription result.
|
16 |
+
"""
|
17 |
client = Client("https://sanchit-gandhi-whisper-jax.hf.space/")
|
18 |
+
result = client.predict(youtube_url, task, return_timestamps, fn_index=7)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
return result
|
20 |
|
21 |
+
|
22 |
+
|
23 |
MODEL_NAME = "openai/whisper-large-v2"
|
24 |
|
25 |
+
|
26 |
demo = gr.Blocks()
|
27 |
|
28 |
EXAMPLES = [
|
29 |
+
["https://www.youtube.com/watch?v=H1YoNlz2LxA", "translate",False],
|
30 |
]
|
31 |
|
32 |
+
|
33 |
yt_transcribe = gr.Interface(
|
34 |
+
fn=transcribe_audio,
|
35 |
inputs=[
|
36 |
gr.inputs.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL"),
|
37 |
gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
|
38 |
+
gr.inputs.Checkbox(label="Return timestamps")
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
],
|
40 |
+
outputs=[gr.outputs.HTML(label="Video"),
|
41 |
+
gr.outputs.Textbox(label="Transcription").style(show_copy_button=True)],
|
42 |
layout="horizontal",
|
43 |
theme=gr.themes.Base(),
|
44 |
+
title="Whisper Large V2: Transcribe YouTube",
|
45 |
description=(
|
46 |
"Transcribe long-form YouTube videos with the click of a button! Demo uses the checkpoint"
|
47 |
f" [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe video files of"
|
|
|
52 |
cache_examples=False
|
53 |
)
|
54 |
|
55 |
+
with demo:
|
56 |
gr.DuplicateButton()
|
57 |
+
gr.TabbedInterface([yt_transcribe], [ "YouTube"])
|
58 |
|
59 |
+
demo.launch(enable_queue=True)
|