EricPeter commited on
Commit
8603428
·
1 Parent(s): 3bd8d03

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -44
app.py DELETED
@@ -1,44 +0,0 @@
1
- import gradio as gr
2
- import torch
3
- import librosa
4
- import json
5
- from transformers import pipeline
6
- from stitched_model import CombinedModel
7
-
8
-
9
- device = "cuda:0" if torch.cuda.is_available() else "cpu"
10
-
11
- model = CombinedModel("ak3ra/wav2vec2-sunbird-speech-lug", "Sunbird/sunbird-mul-en-mbart-merged", device="cpu")
12
-
13
-
14
- def transcribe(audio_file_mic=None, audio_file_upload=None):
15
- if audio_file_mic:
16
- audio_file = audio_file_mic
17
- elif audio_file_upload:
18
- audio_file = audio_file_upload
19
- else:
20
- return "Please upload an audio file or record one"
21
-
22
- # Make sure audio is 16kHz
23
- speech, sample_rate = librosa.load(audio_file)
24
- if sample_rate != 16000:
25
- speech = librosa.resample(speech, orig_sr=sample_rate, target_sr=16000)
26
- speech = torch.tensor([speech])
27
-
28
- with torch.no_grad():
29
- transcription, translation = model({"audio":speech})
30
-
31
- return transcription, translation[0]
32
-
33
- description = '''Luganda to English Speech Translation'''
34
-
35
- iface = gr.Interface(fn=transcribe,
36
- inputs=[
37
- gr.Audio(source="microphone", type="filepath", label="Record Audio"),
38
- gr.Audio(source="upload", type="filepath", label="Upload Audio")],
39
- outputs=[gr.Textbox(label="Transcription"),
40
- gr.Textbox(label="Translation")
41
- ],
42
- description=description
43
- )
44
- iface.launch()