Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
fa0e42d
1
Parent(s):
4373a2f
Initial Commit
Browse files- .gitignore +1 -0
- README.md +1 -1
- app.py +77 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.env
|
README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
---
|
| 2 |
title: Moonshine Tiny STT
|
| 3 |
emoji: 🏢
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: red
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.49.1
|
|
|
|
| 1 |
---
|
| 2 |
title: Moonshine Tiny STT
|
| 3 |
emoji: 🏢
|
| 4 |
+
colorFrom: blue
|
| 5 |
colorTo: red
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.49.1
|
app.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torchaudio
|
| 3 |
+
from transformers import AutoModelForSpeechSeq2Seq, PreTrainedTokenizerFast
|
| 4 |
+
|
| 5 |
+
from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq
|
| 6 |
+
|
| 7 |
+
processor = AutoProcessor.from_pretrained("UsefulSensors/moonshine-tiny")
|
| 8 |
+
model = AutoModelForSpeechSeq2Seq.from_pretrained("UsefulSensors/moonshine-tiny")
|
| 9 |
+
tokenizer = PreTrainedTokenizerFast.from_pretrained("UsefulSensors/moonshine-tiny")
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def transcribe_audio(audio_path):
|
| 13 |
+
if audio_path is None:
|
| 14 |
+
return "Please provide an audio input."
|
| 15 |
+
|
| 16 |
+
try:
|
| 17 |
+
# Load and resample audio
|
| 18 |
+
audio, sr = torchaudio.load(audio_path)
|
| 19 |
+
if sr != 16000:
|
| 20 |
+
audio = torchaudio.functional.resample(audio, sr, 16000)
|
| 21 |
+
|
| 22 |
+
# Get transcription
|
| 23 |
+
tokens = model(audio)
|
| 24 |
+
transcription = tokenizer.decode(tokens[0], skip_special_tokens=True)
|
| 25 |
+
return transcription
|
| 26 |
+
except Exception as e:
|
| 27 |
+
return f"Error processing audio: {str(e)}"
|
| 28 |
+
|
| 29 |
+
# Create Gradio interface
|
| 30 |
+
with gr.Blocks() as demo:
|
| 31 |
+
gr.Markdown("## Audio Transcription App")
|
| 32 |
+
|
| 33 |
+
with gr.Tabs():
|
| 34 |
+
with gr.TabItem("Upload Audio"):
|
| 35 |
+
audio_file = gr.Audio(
|
| 36 |
+
sources=["upload"],
|
| 37 |
+
type="filepath",
|
| 38 |
+
label="Upload Audio File"
|
| 39 |
+
)
|
| 40 |
+
output_text1 = gr.Textbox(
|
| 41 |
+
label="Transcription",
|
| 42 |
+
placeholder="Transcription will appear here..."
|
| 43 |
+
)
|
| 44 |
+
upload_button = gr.Button("Transcribe Uploaded Audio")
|
| 45 |
+
upload_button.click(
|
| 46 |
+
fn=transcribe_audio,
|
| 47 |
+
inputs=audio_file,
|
| 48 |
+
outputs=output_text1
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
with gr.TabItem("Record Audio"):
|
| 52 |
+
audio_mic = gr.Audio(
|
| 53 |
+
sources=["microphone"],
|
| 54 |
+
type="filepath",
|
| 55 |
+
label="Record Audio"
|
| 56 |
+
)
|
| 57 |
+
output_text2 = gr.Textbox(
|
| 58 |
+
label="Transcription",
|
| 59 |
+
placeholder="Transcription will appear here..."
|
| 60 |
+
)
|
| 61 |
+
record_button = gr.Button("Transcribe Recorded Audio")
|
| 62 |
+
record_button.click(
|
| 63 |
+
fn=transcribe_audio,
|
| 64 |
+
inputs=audio_mic,
|
| 65 |
+
outputs=output_text2
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
gr.Markdown("""
|
| 69 |
+
### Instructions:
|
| 70 |
+
1. Choose either 'Upload Audio' or 'Record Audio' tab
|
| 71 |
+
2. Upload an audio file or record using your microphone
|
| 72 |
+
3. Click the respective 'Transcribe' button
|
| 73 |
+
4. Wait for the transcription to appear
|
| 74 |
+
""")
|
| 75 |
+
|
| 76 |
+
if __name__ == "__main__":
|
| 77 |
+
demo.launch()
|