Spaces:

Shokoufeh commited on
Commit
740a68f
1 Parent(s): 8a51868

Add application file

Browse files
Files changed (1) hide show
  1. app.py +30 -4
app.py CHANGED
@@ -1,7 +1,33 @@
 
 
 
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torchaudio
3
+ from sgmse.model import ScoreModel
4
  import gradio as gr
5
 
6
+ # Load the pre-trained model
7
+ model = ScoreModel.load_from_checkpoint("path/to/your/checkpoint.ckpt")
8
 
9
+ def enhance_speech(audio_file):
10
+ # Load and process the audio file
11
+ noisy, sr = torchaudio.load(audio_file)
12
+ noisy = noisy.unsqueeze(0) # Add fake batch dimension if needed
13
+
14
+ # Run the speech enhancement model
15
+ enhanced = model.predict(noisy)
16
+
17
+ # Save the enhanced audio
18
+ output_file = 'enhanced_output.wav'
19
+ torchaudio.save(output_file, enhanced.cpu().squeeze(0), sr)
20
+
21
+ return output_file
22
+
23
+ # Gradio interface setup
24
+ inputs = gr.Audio(label="Input Audio", type="filepath")
25
+ outputs = gr.Audio(label="Output Audio", type="filepath")
26
+ title = "Speech Enhancement using SGMSE"
27
+ description = "This Gradio demo uses the SGMSE model for speech enhancement. Upload your audio file to enhance it."
28
+ article = "<p style='text-align: center'><a href='https://huggingface.co/SP-UHH/speech-enhancement-sgmse' target='_blank'>Model Card</a></p>"
29
+ examples = [
30
+ ['samples/your_example_audio.wav']
31
+ ]
32
+
33
+ gr.Interface(fn=enhance_speech, inputs=inputs, outputs=outputs, title=title, description=description, article=article, examples=examples).launch()