Spaces:
Runtime error
Runtime error
Upload 4 files
Browse files- README.md +4 -4
- app.py +93 -0
- gitattributes.txt +34 -0
- requirements.txt +4 -0
README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
| 1 |
---
|
| 2 |
title: Whisper Can
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 3.29.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
-
license:
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
title: Whisper Can
|
| 3 |
+
emoji: 📚
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 3.29.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: openrail
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import pytube as pt
|
| 5 |
+
from transformers import pipeline
|
| 6 |
+
from huggingface_hub import model_info
|
| 7 |
+
import openai
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def transcribe(microphone, file_upload):
|
| 12 |
+
warn_output = ""
|
| 13 |
+
if (microphone is not None) and (file_upload is not None):
|
| 14 |
+
warn_output = (
|
| 15 |
+
"WARNING: You've uploaded an audio file and used the microphone. "
|
| 16 |
+
"The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
elif (microphone is None) and (file_upload is None):
|
| 20 |
+
return "ERROR: You have to either use the microphone or upload an audio file"
|
| 21 |
+
|
| 22 |
+
file = microphone if microphone is not None else file_upload
|
| 23 |
+
|
| 24 |
+
openai.api_key = "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"
|
| 25 |
+
device = 0 if torch.cuda.is_available() else "cpu"
|
| 26 |
+
res_format = 'srt'
|
| 27 |
+
transcript = openai.Audio.transcribe(model="whisper-1", file=open(file, 'rb'), response_format=res_format, prompt='请使用书面语')
|
| 28 |
+
|
| 29 |
+
text = transcript
|
| 30 |
+
|
| 31 |
+
return warn_output + text
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def _return_yt_html_embed(yt_url):
|
| 35 |
+
video_id = yt_url.split("?v=")[-1]
|
| 36 |
+
HTML_str = (
|
| 37 |
+
f'<center> <iframe width="500" height="320" src="https://www.youtube.com/embed/{video_id}"> </iframe>'
|
| 38 |
+
" </center>"
|
| 39 |
+
)
|
| 40 |
+
return HTML_str
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def yt_transcribe(yt_url):
|
| 44 |
+
yt = pt.YouTube(yt_url)
|
| 45 |
+
html_embed_str = _return_yt_html_embed(yt_url)
|
| 46 |
+
stream = yt.streams.filter(only_audio=True)[0]
|
| 47 |
+
stream.download(filename="audio.mp3")
|
| 48 |
+
|
| 49 |
+
openai.api_key = "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"
|
| 50 |
+
device = 0 if torch.cuda.is_available() else "cpu"
|
| 51 |
+
res_format = 'srt'
|
| 52 |
+
transcript = openai.Audio.transcribe(model="whisper-1", file=open('audio.mp3', 'rb'), response_format=res_format, prompt='请使用书面语')
|
| 53 |
+
|
| 54 |
+
text = transcript
|
| 55 |
+
|
| 56 |
+
return html_embed_str, text
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
demo = gr.Blocks()
|
| 60 |
+
|
| 61 |
+
mf_transcribe = gr.Interface(
|
| 62 |
+
fn=transcribe,
|
| 63 |
+
inputs=[
|
| 64 |
+
gr.inputs.Audio(source="microphone", type="filepath", optional=True),
|
| 65 |
+
gr.inputs.Audio(source="upload", type="filepath", optional=True),
|
| 66 |
+
],
|
| 67 |
+
outputs="text",
|
| 68 |
+
layout="horizontal",
|
| 69 |
+
theme="huggingface",
|
| 70 |
+
title="Whisper Demo: Transcribe Audio",
|
| 71 |
+
description=(
|
| 72 |
+
"Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the Whisper."
|
| 73 |
+
),
|
| 74 |
+
allow_flagging="never",
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
yt_transcribe = gr.Interface(
|
| 78 |
+
fn=yt_transcribe,
|
| 79 |
+
inputs=[gr.inputs.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL")],
|
| 80 |
+
outputs=["html", "text"],
|
| 81 |
+
layout="horizontal",
|
| 82 |
+
theme="huggingface",
|
| 83 |
+
title="Whisper Demo: Transcribe YouTube",
|
| 84 |
+
description=(
|
| 85 |
+
"Transcribe long-form YouTube videos with the click of a button! Demo uses the Whisper."
|
| 86 |
+
),
|
| 87 |
+
allow_flagging="never",
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
with demo:
|
| 91 |
+
gr.TabbedInterface([mf_transcribe, yt_transcribe], ["Transcribe Audio", "Transcribe YouTube"])
|
| 92 |
+
|
| 93 |
+
demo.launch(enable_queue=True)
|
gitattributes.txt
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
git+https://github.com/huggingface/transformers
|
| 2 |
+
torch
|
| 3 |
+
pytube
|
| 4 |
+
openai
|