Andrei-Iulian SĂCELEANU commited on
Commit
eaee399
1 Parent(s): 5506e99

added examples sections

Browse files
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import re
 
2
  import gradio as gr
3
  import librosa
4
  import numpy as np
@@ -119,12 +120,21 @@ def ssl_predict2(audio_file, model_type):
119
  d[k] = float(v)
120
  return d
121
 
 
 
 
 
 
 
 
 
122
  with gr.Blocks() as ssl_interface:
123
 
124
  with gr.Tab("Text (RO-Offense)"):
125
  with gr.Row():
126
  with gr.Column():
127
- in_text = gr.Textbox(label="Input text")
 
128
  model_list = gr.Dropdown(
129
  choices=["fixmatch", "freematch", "mixmatch", "contrastive_reg", "label_propagation"],
130
  max_choices=1,
@@ -137,9 +147,25 @@ with gr.Blocks() as ssl_interface:
137
  clear_btn = gr.Button(value="Clear")
138
  submit_btn = gr.Button(value="Submit")
139
 
 
 
 
 
 
 
140
  with gr.Column():
141
  out_field = gr.Label(num_top_classes=4, label="Prediction")
142
 
 
 
 
 
 
 
 
 
 
 
143
  submit_btn.click(
144
  fn=ssl_predict,
145
  inputs=[in_text, model_list],
@@ -172,6 +198,13 @@ with gr.Blocks() as ssl_interface:
172
  clear_btn2 = gr.Button(value="Clear")
173
  submit_btn2 = gr.Button(value="Submit")
174
 
 
 
 
 
 
 
 
175
  with gr.Column():
176
  out_field2 = gr.Label(num_top_classes=6, label="Prediction")
177
 
@@ -188,4 +221,10 @@ with gr.Blocks() as ssl_interface:
188
  queue=False
189
  )
190
 
 
 
 
 
 
 
191
  ssl_interface.launch(server_name="0.0.0.0", server_port=7860)
 
1
  import re
2
+ import os
3
  import gradio as gr
4
  import librosa
5
  import numpy as np
 
120
  d[k] = float(v)
121
  return d
122
 
123
+ text_types = ["text", "password"]
124
+ with open(file="examples.txt", mode="r", encoding="UTF-8") as fin:
125
+ lines = [elem[:-1] for elem in fin.readlines()]
126
+
127
+ DATA_DIR = os.path.abspath("./audio_data")
128
+ with open(file="audio_examples.txt", mode="r", encoding="UTF-8") as fin:
129
+ lines2 = [os.path.join(DATA_DIR, elem.strip()) for elem in fin.readlines()]
130
+
131
  with gr.Blocks() as ssl_interface:
132
 
133
  with gr.Tab("Text (RO-Offense)"):
134
  with gr.Row():
135
  with gr.Column():
136
+ in_text = gr.Textbox(label="Input text",type="password")
137
+ safe_view = gr.Checkbox(value=True,label="Safe view")
138
  model_list = gr.Dropdown(
139
  choices=["fixmatch", "freematch", "mixmatch", "contrastive_reg", "label_propagation"],
140
  max_choices=1,
 
147
  clear_btn = gr.Button(value="Clear")
148
  submit_btn = gr.Button(value="Submit")
149
 
150
+ ds = gr.Dataset(
151
+ components=[gr.Textbox(visible=False),gr.Textbox(visible=False)],
152
+ headers=["Id","Expected class"],
153
+ samples=[["1","ABUSE"],["2","INSULT"],["3","PROFANITY"],["4","OTHER"]],
154
+ type="index"
155
+ )
156
  with gr.Column():
157
  out_field = gr.Label(num_top_classes=4, label="Prediction")
158
 
159
+ safe_view.change(
160
+ fn= lambda checked: gr.update(type=text_types[int(checked)]),
161
+ inputs=safe_view,
162
+ outputs=in_text
163
+ )
164
+ ds.click(
165
+ fn=lambda idx: gr.update(value=lines[idx].split("##")[0]),
166
+ inputs=ds,
167
+ outputs=in_text
168
+ )
169
  submit_btn.click(
170
  fn=ssl_predict,
171
  inputs=[in_text, model_list],
 
198
  clear_btn2 = gr.Button(value="Clear")
199
  submit_btn2 = gr.Button(value="Submit")
200
 
201
+ ds2 = gr.Dataset(
202
+ components=[gr.Textbox(visible=False),gr.Textbox(visible=False)],
203
+ headers=["Id","Expected class"],
204
+ samples=[["1","Laughter"],["2","Cough"],["3","Sneeze"],["4","Throatclearing"]],
205
+ type="index"
206
+ )
207
+
208
  with gr.Column():
209
  out_field2 = gr.Label(num_top_classes=6, label="Prediction")
210
 
 
221
  queue=False
222
  )
223
 
224
+ ds2.click(
225
+ fn=lambda idx: gr.update(value=lines2[idx]),
226
+ inputs=ds2,
227
+ outputs=audio_file
228
+ )
229
+
230
  ssl_interface.launch(server_name="0.0.0.0", server_port=7860)
audio_data/f3198_0_throatclearing.wav ADDED
Binary file (71 kB). View file
 
audio_data/o0337_0_laughter.wav ADDED
Binary file (90.2 kB). View file
 
audio_data/o0338_0_cough.wav ADDED
Binary file (123 kB). View file
 
audio_data/o3362_0_sneeze.wav ADDED
Binary file (101 kB). View file
 
audio_examples.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ o0337_0_laughter.wav
2
+ o0338_0_cough.wav
3
+ o3362_0_sneeze.wav
4
+ f3198_0_throatclearing.wav
examples.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ duce ti va de aici cu panaramele astea ## ABUSE
2
+ echipa asta nu mai merge deloc bine. sunt niste terminati prosti ## INSULT
3
+ Cum poti sa renunti la WTA Tour si sa il lasi in intregime la concurenta ? Cine naiba se mai uita la turneele ATP ? Romania nu a mai avut un sportiv mare de cca 25 de ani, Simona Halep e singurul bun national in acest moment si are milioane de fani. Halal conducere la Telekom... ## PROFANITY
4
+ un meci uimitor, cea mai buna prestatie din ultimele sezoane. felicitari ## OTHER