Spaces:
Sleeping
Sleeping
Chandranshu Jain
commited on
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import os
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
#Text to text
|
| 7 |
+
#translator = pipeline(task="translation",
|
| 8 |
+
# model="facebook/nllb-200-distilled-600M",
|
| 9 |
+
# torch_dtype=torch.bfloat16)
|
| 10 |
+
#Text to audio
|
| 11 |
+
pipe = pipeline("text-to-speech", model="suno/bark-small",
|
| 12 |
+
torch_dtype=torch.bfloat16)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
demo = gr.Blocks()
|
| 16 |
+
def transcribe_speech(filepath):
|
| 17 |
+
if filepath is None:
|
| 18 |
+
gr.Warning("No text found, please retry.")
|
| 19 |
+
return ""
|
| 20 |
+
narrated_text=pipe(filepath)
|
| 21 |
+
return narrated_text
|
| 22 |
+
|
| 23 |
+
mic_transcribe = gr.Interface(
|
| 24 |
+
fn=transcribe_speech,
|
| 25 |
+
inputs=gr.Textbox(label="Text",lines=3),
|
| 26 |
+
outputs="audio",
|
| 27 |
+
allow_flagging="never")
|
| 28 |
+
|
| 29 |
+
file_transcribe = gr.Interface(
|
| 30 |
+
fn=transcribe_speech,
|
| 31 |
+
inputs=gr.Audio(sources="upload",
|
| 32 |
+
type="filepath"),
|
| 33 |
+
outputs="audio",
|
| 34 |
+
#outputs=gr.Audio(label="Translated Message"),
|
| 35 |
+
allow_flagging="never"
|
| 36 |
+
)
|
| 37 |
+
with demo:
|
| 38 |
+
gr.TabbedInterface(
|
| 39 |
+
[mic_transcribe],
|
| 40 |
+
["Transcribe Microphone"],
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
demo.launch(share=True)
|
| 44 |
+
demo.close()
|