UpCoder commited on
Commit
8c5429a
·
verified ·
1 Parent(s): 937c17a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ print("Loading the Islomov STT model onto Hugging Face servers...")
5
+
6
+ # Load the model. (HF Free Spaces use CPUs, so we don't specify a cuda device here)
7
+ stt_pipeline = pipeline(
8
+ "automatic-speech-recognition",
9
+ model="islomov/rubaistt_v2_medium"
10
+ )
11
+
12
+ def transcribe_for_api(audio_filepath):
13
+ # Failsafe if the API receives an empty request
14
+ if audio_filepath is None:
15
+ return "Error: No audio file received by the Space."
16
+
17
+ try:
18
+ # Pass the audio file directly into the model
19
+ result = stt_pipeline(audio_filepath)
20
+ return result["text"].strip()
21
+ except Exception as e:
22
+ return f"Error during transcription: {str(e)}"
23
+
24
+ # Build the Gradio interface
25
+ # We set type="filepath" so Gradio automatically saves the incoming API audio to a temporary file
26
+ interface = gr.Interface(
27
+ fn=transcribe_for_api,
28
+ inputs=gr.Audio(type="filepath", label="Input Audio"),
29
+ outputs=gr.Textbox(label="Uzbek Transcription"),
30
+ title="b-til.uz STT API Engine",
31
+ description="This Space processes audio for the b-til.uz language platform."
32
+ )
33
+
34
+ # Launch the server and enable the API
35
+ if __name__ == "__main__":
36
+ interface.launch()