Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,43 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
return str(e)
|
14 |
|
15 |
-
|
16 |
-
with gr.Blocks(fill_height=True) as demo:
|
17 |
-
with gr.Sidebar():
|
18 |
-
gr.Markdown("# SeeSay - Powered by Sesame CSM")
|
19 |
-
gr.Markdown("This Space extracts captions from images and generates expressive speech using CSM.")
|
20 |
-
gr.Markdown("Sign in with your Hugging Face account to access the model.")
|
21 |
-
button = gr.LoginButton("Sign in")
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
31 |
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
4 |
+
from datasets import load_dataset
|
5 |
|
6 |
+
device = "cpu"
|
7 |
+
torch_dtype = torch.float32
|
8 |
|
9 |
+
# Load the Whisper model
|
10 |
+
model_id = "openai/whisper-large-v3-turbo"
|
11 |
+
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
12 |
+
model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True
|
13 |
+
)
|
14 |
+
model.to(device)
|
|
|
15 |
|
16 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
+
pipe = pipeline(
|
19 |
+
"automatic-speech-recognition",
|
20 |
+
model=model,
|
21 |
+
tokenizer=processor.tokenizer,
|
22 |
+
feature_extractor=processor.feature_extractor,
|
23 |
+
torch_dtype=torch_dtype,
|
24 |
+
device=device,
|
25 |
+
)
|
26 |
|
27 |
+
def transcribe(audio_path):
|
28 |
+
try:
|
29 |
+
# Transcribe the audio using Whisper
|
30 |
+
result = pipe(audio_path)
|
31 |
+
return result["text"]
|
32 |
+
except Exception as e:
|
33 |
+
return str(e)
|
34 |
|
35 |
+
demo = gr.Interface(
|
36 |
+
fn=transcribe,
|
37 |
+
inputs=gr.Audio(type="filepath"),
|
38 |
+
outputs=gr.Textbox(),
|
39 |
+
title="Whisper Speech Recognition",
|
40 |
+
description="Upload an audio file to transcribe using Whisper large-v3-turbo."
|
41 |
+
)
|
42 |
|
43 |
+
demo.launch(share=True)
|