bilal6913 commited on
Commit
0917860
·
verified ·
1 Parent(s): fb211a0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torchaudio
3
+ import torch
4
+
5
+ # Load your trained model (replace with your model loading logic)
6
+ # model = ... (load your model here)
7
+
8
+ def transcribe(audio):
9
+ # Load the audio file
10
+ waveform, sample_rate = torchaudio.load(audio)
11
+
12
+ # Preprocess the audio (if necessary)
13
+ # Here, we assume that the model expects a specific input format
14
+ # For example, convert to mono if it's stereo
15
+ if waveform.shape[0] > 1: # If stereo, take the first channel
16
+ waveform = waveform[0, :].unsqueeze(0)
17
+
18
+ # Normalize the waveform (if necessary)
19
+ waveform = waveform / waveform.abs().max()
20
+
21
+ # Predict text from audio
22
+ # Make sure to set the model to evaluation mode
23
+ # model.eval()
24
+ with torch.no_grad():
25
+ # Replace this with your model's prediction logic
26
+ # predicted_text = model(waveform)
27
+
28
+ # Dummy output for illustration
29
+ predicted_text = "This is a placeholder for the transcribed text."
30
+
31
+ return predicted_text
32
+
33
+ # Create Gradio interface
34
+ interface = gr.Interface(
35
+ fn=transcribe,
36
+ inputs=gr.Audio(source="upload", type="filepath"),
37
+ outputs="text",
38
+ title="Speech-to-Text Transcription",
39
+ description="Upload an audio file to transcribe it into text."
40
+ )
41
+
42
+ if __name__ == "__main__":
43
+ interface.launch()