Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,35 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
| 3 |
+
from datasets import load_dataset
|
| 4 |
+
import torch
|
| 5 |
|
| 6 |
+
# Load Whisper model and processor
|
| 7 |
+
model_name = "openai/whisper-large-v3-turbo"
|
| 8 |
+
processor = WhisperProcessor.from_pretrained(model_name)
|
| 9 |
+
model = WhisperForConditionalGeneration.from_pretrained(model_name)
|
| 10 |
+
|
| 11 |
+
# Load dataset (bigcode/the-stack)
|
| 12 |
+
dataset = load_dataset("bigcode/the-stack", data_dir="data/html")
|
| 13 |
+
|
| 14 |
+
def transcribe(audio):
|
| 15 |
+
# Process audio for transcription
|
| 16 |
+
audio_input = processor(audio, return_tensors="pt").input_values
|
| 17 |
+
with torch.no_grad():
|
| 18 |
+
logits = model(audio_input).logits
|
| 19 |
+
predicted_ids = torch.argmax(logits, dim=-1)
|
| 20 |
+
transcription = processor.batch_decode(predicted_ids)
|
| 21 |
+
|
| 22 |
+
# Return the transcription
|
| 23 |
+
return transcription[0]
|
| 24 |
+
|
| 25 |
+
# Gradio interface
|
| 26 |
+
iface = gr.Interface(
|
| 27 |
+
fn=transcribe,
|
| 28 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
| 29 |
+
outputs="text",
|
| 30 |
+
title="Whisper Transcription for Developers",
|
| 31 |
+
description="Transcribe developer-related terms using Whisper and bigcode dataset for contextual support."
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
# Launch the Gradio app
|
| 35 |
+
iface.launch()
|