rohitp1 commited on
Commit
f69cfe5
·
1 Parent(s): 4f13506

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -15
app.py CHANGED
@@ -26,25 +26,29 @@ feat_ext = WhisperFeatureExtractor.from_pretrained("rohitp1/kkkh_whisper_small_d
26
 
27
  p = pipeline('automatic-speech-recognition', model=model, tokenizer=tokenizer, feature_extractor=feat_ext)
28
 
29
- def transcribe(audio, state=""):
 
 
 
 
30
  time.sleep(3)
31
  text = p(audio)["text"]
32
- state = text + " "
33
- return state, state
34
 
35
 
36
 
37
- gr.Interface(
38
- fn=transcribe,
39
- inputs=[
40
- gr.inputs.Audio(source="microphone", type="filepath"),
41
- 'state'
42
- ],
43
- outputs=[
44
- "textbox",
45
- "state"
46
- ],
47
- live=False).launch()
48
 
49
 
50
  # demo = gr.load(
@@ -55,4 +59,64 @@ gr.Interface(
55
  # api_key="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"
56
  # )
57
 
58
- # demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  p = pipeline('automatic-speech-recognition', model=model, tokenizer=tokenizer, feature_extractor=feat_ext)
28
 
29
+ def transcribe(mic_input, upl_input):
30
+ if mic_input:
31
+ audio = mic_input
32
+ else:
33
+ audio = upl_input
34
  time.sleep(3)
35
  text = p(audio)["text"]
36
+ # state = text + " "
37
+ return text
38
 
39
 
40
 
41
+ # gr.Interface(
42
+ # fn=transcribe,
43
+ # inputs=[
44
+ # gr.inputs.Audio(source="microphone", type="filepath"),
45
+ # 'state'
46
+ # ],
47
+ # outputs=[
48
+ # "textbox",
49
+ # "state"
50
+ # ],
51
+ # live=False).launch()
52
 
53
 
54
  # demo = gr.load(
 
59
  # api_key="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"
60
  # )
61
 
62
+ # demo.launch()
63
+
64
+ def clear_inputs_and_outputs():
65
+ return [None, None, None]
66
+
67
+ # Main function
68
+ if __name__ == "__main__":
69
+ demo = gr.Blocks()
70
+
71
+ with demo:
72
+ gr.Markdown(
73
+ """
74
+ <center><h1>English speaker accent recognition using Transfer Learning</h1></center> \
75
+ This space is a demo of an English (precisely UK & Ireland) accent classification model using Keras.<br> \
76
+ In this space, you can record your voice or upload a wav file and the model will predict the English accent spoken in the audio<br><br>
77
+ """
78
+ )
79
+ with gr.Row():
80
+ ## Input
81
+ with gr.Column():
82
+ mic_input = gr.Audio(source="microphone", label="Record your own voice")
83
+ upl_input = gr.Audio(
84
+ source="upload", type="filepath", label="Upload a wav file"
85
+ )
86
+
87
+ with gr.Row():
88
+ clr_btn = gr.Button(value="Clear", variant="secondary")
89
+ prd_btn = gr.Button(value="Predict")
90
+
91
+ # Outputs
92
+ with gr.Column():
93
+ lbl_output = gr.Label(label="Top Predictions")
94
+ # with gr.Group():
95
+ # gr.Markdown("<center>Prediction per time slot</center>")
96
+ # plt_output = gr.Plot(
97
+ # label="Prediction per time slot", show_label=False
98
+ # )
99
+
100
+ # Credits
101
+ with gr.Row():
102
+ gr.Markdown(
103
+ """
104
+ <h4>Credits</h4>
105
+ Author: <a href="https://twitter.com/fadibadine"> Fadi Badine</a>.<br>
106
+ Based on the following Keras example <a href="https://keras.io/examples/audio/uk_ireland_accent_recognition"> English speaker accent recognition using Transfer Learning</a> by Fadi Badine<br>
107
+ Check out the model <a href="https://huggingface.co/keras-io/english-speaker-accent-recognition-using-transfer-learning">here</a>
108
+ """
109
+ )
110
+
111
+ clr_btn.click(
112
+ fn=clear_inputs_and_outputs,
113
+ inputs=[],
114
+ outputs=[mic_input, upl_input, lbl_output],
115
+ )
116
+ prd_btn.click(
117
+ fn=transcribe,
118
+ inputs=[mic_input, upl_input],
119
+ outputs=[lbl_output],
120
+ )
121
+
122
+ demo.launch(debug=True)