supernovamutinda
commited on
Commit
·
69b0eb6
1
Parent(s):
1c42ab6
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,7 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
2 |
|
3 |
|
4 |
with st.sidebar:
|
@@ -24,3 +27,60 @@ if choice == "Events":
|
|
24 |
|
25 |
if choice == "Transcribe, audio to Text":
|
26 |
st.title("Tired of listening long audio? convert to Text")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import gradio as gr
|
3 |
+
import os
|
4 |
+
from gradio_client import Client
|
5 |
|
6 |
|
7 |
with st.sidebar:
|
|
|
27 |
|
28 |
if choice == "Transcribe, audio to Text":
|
29 |
st.title("Tired of listening long audio? convert to Text")
|
30 |
+
|
31 |
+
def transcribe_audio(youtube_url: str, task: str = "transcribe", return_timestamps: bool = False, api_name: str = "/predict_2") -> dict:
|
32 |
+
"""
|
33 |
+
Transcribe audio from a given YouTube URL using a specified model.
|
34 |
+
Parameters:
|
35 |
+
- youtube_url (str): The YouTube URL to transcribe.
|
36 |
+
- task (str, optional): The task to perform. Default is "transcribe".
|
37 |
+
- return_timestamps (bool, optional): Whether to return timestamps. Default is True.
|
38 |
+
- api_name (str, optional): The API endpoint to use. Default is "/predict_2".
|
39 |
+
Returns:
|
40 |
+
- dict: The transcription result.
|
41 |
+
"""
|
42 |
+
client = Client("https://sanchit-gandhi-whisper-jax.hf.space/")
|
43 |
+
result = client.predict(youtube_url, task, return_timestamps, fn_index=7)
|
44 |
+
return result
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
MODEL_NAME = "openai/whisper-large-v2"
|
49 |
+
|
50 |
+
|
51 |
+
demo = gr.Blocks()
|
52 |
+
|
53 |
+
EXAMPLES = [
|
54 |
+
["https://www.youtube.com/watch?v=H1YoNlz2LxA", "translate",False],
|
55 |
+
]
|
56 |
+
|
57 |
+
|
58 |
+
yt_transcribe = gr.Interface(
|
59 |
+
fn=transcribe_audio,
|
60 |
+
inputs=[
|
61 |
+
gr.inputs.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL"),
|
62 |
+
gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
|
63 |
+
gr.inputs.Checkbox(label="Return timestamps")
|
64 |
+
],
|
65 |
+
outputs=[gr.outputs.HTML(label="Video"),
|
66 |
+
gr.outputs.Textbox(label="Transcription").style(show_copy_button=True)],
|
67 |
+
layout="horizontal",
|
68 |
+
theme=gr.themes.Base(),
|
69 |
+
title="Whisper Large V2: Transcribe YouTube",
|
70 |
+
description=(
|
71 |
+
"Transcribe long-form YouTube videos with the click of a button! Demo uses the checkpoint"
|
72 |
+
f" [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe video files of"
|
73 |
+
" arbitrary length."
|
74 |
+
),
|
75 |
+
allow_flagging="never",
|
76 |
+
examples=EXAMPLES,
|
77 |
+
cache_examples=False
|
78 |
+
)
|
79 |
+
|
80 |
+
with demo:
|
81 |
+
gr.DuplicateButton()
|
82 |
+
gr.TabbedInterface([yt_transcribe], [ "YouTube"])
|
83 |
+
|
84 |
+
demo.launch(enable_queue=True)
|
85 |
+
|
86 |
+
|