Ariamehr commited on
Commit
41af2be
·
verified ·
1 Parent(s): 8356182

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -7
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
3
  import torch
4
  import librosa
 
5
 
6
  # Model details
7
  models = {
@@ -31,25 +32,53 @@ def transcribe(audio, model_name):
31
  transcription = processor.batch_decode(predicted_ids)[0]
32
  return transcription
33
 
 
 
 
 
 
 
 
34
  # Gradio app
35
  with gr.Blocks() as demo:
 
 
36
  gr.Markdown("""
37
  <h1 style="color: #4CAF50; text-align: center;">Persian Speech-to-Text Models</h1>
38
  <p style="text-align: center;">Test the best Persian STT models in one place!</p>
39
  """)
40
 
41
  with gr.Row():
42
- audio_input = gr.Audio(type="filepath", label="Upload your audio file")
43
- model_dropdown = gr.Dropdown(
44
- choices=list(models.keys()),
45
- label="Select Model",
46
- value="m3hrdadfi/wav2vec2-large-xlsr-persian-v3"
47
- )
 
 
 
 
 
 
 
 
48
 
49
- output_text = gr.Textbox(label="Transcription", lines=5, placeholder="The transcription will appear here...")
 
 
 
 
 
50
 
51
  transcribe_button = gr.Button("Transcribe")
52
 
 
 
 
 
 
 
53
  transcribe_button.click(
54
  fn=transcribe,
55
  inputs=[audio_input, model_dropdown],
 
2
  from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
3
  import torch
4
  import librosa
5
+ import os
6
 
7
  # Model details
8
  models = {
 
32
  transcription = processor.batch_decode(predicted_ids)[0]
33
  return transcription
34
 
35
+ # Read HTML banner
36
+ if os.path.exists("banner.html"):
37
+ with open("banner.html", "r", encoding="utf-8") as file:
38
+ banner = file.read()
39
+ else:
40
+ banner = "<h1 style='color: red; text-align: center;'>Banner file not found!</h1>"
41
+
42
  # Gradio app
43
  with gr.Blocks() as demo:
44
+ gr.HTML(banner)
45
+
46
  gr.Markdown("""
47
  <h1 style="color: #4CAF50; text-align: center;">Persian Speech-to-Text Models</h1>
48
  <p style="text-align: center;">Test the best Persian STT models in one place!</p>
49
  """)
50
 
51
  with gr.Row():
52
+ with gr.Column():
53
+ audio_input = gr.Audio(
54
+ source="microphone", type="filepath", label="Upload or Record Audio",
55
+ elem_id="audio-upload"
56
+ )
57
+ model_dropdown = gr.Dropdown(
58
+ choices=list(models.keys()),
59
+ label="Select Model",
60
+ value="m3hrdadfi/wav2vec2-large-xlsr-persian-v3"
61
+ )
62
+
63
+ # Add Test Audio Button
64
+ def use_test_audio():
65
+ return "Test-Audio.ogg"
66
 
67
+ test_audio_button = gr.Button("Use Test Audio")
68
+
69
+ with gr.Column():
70
+ output_text = gr.Textbox(
71
+ label="Transcription", lines=5, placeholder="The transcription will appear here..."
72
+ )
73
 
74
  transcribe_button = gr.Button("Transcribe")
75
 
76
+ test_audio_button.click(
77
+ fn=use_test_audio,
78
+ inputs=[],
79
+ outputs=[audio_input]
80
+ )
81
+
82
  transcribe_button.click(
83
  fn=transcribe,
84
  inputs=[audio_input, model_dropdown],