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2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
from df.enhance import enhance, init_df, load_audio, save_audio
|
5 |
+
import time
|
6 |
+
import os
|
7 |
+
import gradio as gr
|
8 |
+
import re
|
9 |
+
from gradio.themes.base import Base
|
10 |
+
from datasets import load_dataset
|
11 |
+
from datasets import Dataset,DatasetDict
|
12 |
+
import librosa
|
13 |
+
import torch
|
14 |
+
|
15 |
+
model_enhance, df_state, _ = init_df()
|
16 |
+
def Read_DataSet(link):
|
17 |
+
dataset = load_dataset(link,token=os.environ.get("auth_acess_data"))
|
18 |
+
df = dataset["train"].to_pandas()
|
19 |
+
return df
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
def remove_nn(wav, sample_rate=16000):
|
25 |
+
|
26 |
+
audio=librosa.resample(wav,orig_sr=sample_rate,target_sr=df_state.sr(),)
|
27 |
+
|
28 |
+
audio=torch.tensor([audio])
|
29 |
+
# audio, _ = load_audio('full_generation.wav', sr=df_state.sr())
|
30 |
+
print(audio)
|
31 |
+
|
32 |
+
enhanced = enhance(model_enhance, df_state, audio)
|
33 |
+
print(enhanced)
|
34 |
+
# save_audio("enhanced.wav", enhanced, df_state.sr())
|
35 |
+
audiodata=librosa.resample(enhanced[0].numpy(),orig_sr=df_state.sr(),target_sr=sample_rate)
|
36 |
+
|
37 |
+
return 16000, audiodata/np.max(audiodata)
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
|
42 |
+
class DataViewerApp:
|
43 |
+
def __init__(self,df):
|
44 |
+
#df=Read_DataSet(link)
|
45 |
+
self.df=df
|
46 |
+
# self.df1=df
|
47 |
+
self.data =self.df[['text','speaker_id','secs','flag']]
|
48 |
+
self.dataa =self.df[['text','speaker_id','secs','flag']]
|
49 |
+
self.sdata =self.df['audio'].to_list() # Separate audio data storage
|
50 |
+
self.current_page = 0
|
51 |
+
self.current_selected = -1
|
52 |
+
self.speaker_id= -1
|
53 |
+
class Seafoam(Base):
|
54 |
+
pass
|
55 |
+
self.seafoam = Seafoam()
|
56 |
+
|
57 |
+
#self.data =df[['text','speaker_id']]
|
58 |
+
#self.sdata = df['audio'].to_list() # Separate audio data storage
|
59 |
+
#self.current_page = 0
|
60 |
+
#self.current_selected = -1
|
61 |
+
def set1(self,df):
|
62 |
+
self.data =df[['text','speaker_id','secs','flag']]
|
63 |
+
self.sdata =df['audio'].to_list()
|
64 |
+
return self.get_page_data(self.current_page)
|
65 |
+
def settt(self,df):
|
66 |
+
self.df=pd.DataFrame()
|
67 |
+
self.data =pd.DataFrame()
|
68 |
+
self.sdata =[]
|
69 |
+
self.df=df
|
70 |
+
self.data =df[['text','speaker_id','secs','flag']]
|
71 |
+
self.dataa =df[['text','speaker_id','secs','flag']]
|
72 |
+
self.sdata =df['audio'].to_list()
|
73 |
+
self.current_page = 0
|
74 |
+
self.current_selected =1
|
75 |
+
self.speaker_id= -1
|
76 |
+
return self.data
|
77 |
+
def clear(self,text):
|
78 |
+
text=re.sub(r'[a-zA-Z]', '', text)
|
79 |
+
return text
|
80 |
+
def clearenglish(self):
|
81 |
+
for i in range(len(self.df)):
|
82 |
+
x=self.clear(self.df['text'][i])
|
83 |
+
x1=self.df['text'][i]
|
84 |
+
if x!=x1:
|
85 |
+
self.df.drop(i, inplace=True)
|
86 |
+
|
87 |
+
self.df.reset_index(drop=True, inplace=True)
|
88 |
+
return self.settt(self.df)
|
89 |
+
def splitt(self,link,num):
|
90 |
+
df=download_youtube_video(link,num)
|
91 |
+
v=self.settt(df)
|
92 |
+
return self.get_page_data(self.current_page),len(v)
|
93 |
+
def getdataset(self,link):
|
94 |
+
self.link_dataset=link
|
95 |
+
df=Read_DataSet(link)
|
96 |
+
v=self.settt(df)
|
97 |
+
return self.get_page_data(self.current_page),len(v),self.link_dataset
|
98 |
+
def remove_hamza_from_alif_and_symbols(self,text):
|
99 |
+
text = re.sub(r"[أإآ]", "ا", text)
|
100 |
+
text = re.sub(r"ٱ", "ا", text)
|
101 |
+
text = re.sub(r"[_\-\+\,\(\)]", " ", text)
|
102 |
+
text = re.sub(r"\d", " ", text)
|
103 |
+
return text
|
104 |
+
def save_row(self, text,data_oudio):
|
105 |
+
if text!="" :
|
106 |
+
row = self.data.iloc[self.current_selected]
|
107 |
+
row['text'] = text
|
108 |
+
row['flag']=1
|
109 |
+
self.data.iloc[self.current_selected] = row
|
110 |
+
sr,audio=data_oudio
|
111 |
+
if sr!=16000:
|
112 |
+
audio=audio.astype(np.float32)
|
113 |
+
audio/=np.max(np.abs(audio))
|
114 |
+
audio=librosa.resample(audio,orig_sr=sr,target_sr=16000)
|
115 |
+
|
116 |
+
|
117 |
+
|
118 |
+
|
119 |
+
|
120 |
+
self.sdata[self.current_selected] = audio
|
121 |
+
self.df['text'][self.current_selected] =text
|
122 |
+
self.df['audio'][self.current_selected] = audio
|
123 |
+
self.df['flag'][self.current_selected] =1
|
124 |
+
return self.get_page_data(self.current_page),None,""
|
125 |
+
def GetDataset_2(self,filename,ds=1.5):
|
126 |
+
audios_data = []
|
127 |
+
audios_samplerate = []
|
128 |
+
num_specker=[]
|
129 |
+
texts=[]
|
130 |
+
secs=[]
|
131 |
+
|
132 |
+
audiodata,samplerate = librosa.load(filename, sr=16000) # Removed extra indent here
|
133 |
+
audios_data.append(audiodata*ds)
|
134 |
+
audios_samplerate.append(samplerate)
|
135 |
+
texts.append(filename.replace('.wav',''))
|
136 |
+
secs.append(round(len(audiodata)/samplerate,2))
|
137 |
+
df = pd.DataFrame()
|
138 |
+
df['secs'] = secs
|
139 |
+
df['audio'] = audios_data
|
140 |
+
df['samplerate'] = audios_samplerate
|
141 |
+
df['text'] =os.path.splitext(os.path.basename(filename))[0]
|
142 |
+
df['speaker_id'] =self.speaker_id
|
143 |
+
df['_speaker_id'] =self.speaker_id
|
144 |
+
df['flag']=1
|
145 |
+
df = df[['text','audio','samplerate','secs','speaker_id','_speaker_id','flag']]
|
146 |
+
self.df = pd.concat([self.df, df], axis=0, ignore_index=True)
|
147 |
+
self.data =self.df[['text','speaker_id','secs','flag']]
|
148 |
+
self.sdata =self.df['audio'].to_list()
|
149 |
+
|
150 |
+
return self.get_page_data(self.current_page)
|
151 |
+
def trim_audio(self, text,data_oudio):
|
152 |
+
if text!="" :
|
153 |
+
audios_data = []
|
154 |
+
audios_samplerate = []
|
155 |
+
sr,audio=data_oudio
|
156 |
+
audio=audio.astype(np.float32)
|
157 |
+
audio/=np.max(np.abs(audio))
|
158 |
+
audio=librosa.resample(audio,orig_sr=sr,target_sr=16000)
|
159 |
+
audios_data.append(audio)
|
160 |
+
secs=round(len(audios_data)/16000,2)
|
161 |
+
audios_samplerate.append(16000)
|
162 |
+
df = pd.DataFrame()
|
163 |
+
df['secs'] = secs
|
164 |
+
df['audio'] =[ audio]
|
165 |
+
df['samplerate'] = 16000
|
166 |
+
df['text'] =text
|
167 |
+
df['speaker_id'] =self.speaker_id
|
168 |
+
df['_speaker_id'] =self.speaker_id
|
169 |
+
df['flag']=1
|
170 |
+
df = df[['text','audio','samplerate','secs','speaker_id','_speaker_id','flag']]
|
171 |
+
self.df = pd.concat([self.df, df], axis=0, ignore_index=True)
|
172 |
+
self.data =self.df[['text','speaker_id','secs','flag']]
|
173 |
+
self.sdata =self.df['audio'].to_list()
|
174 |
+
return self.get_page_data(self.current_page),None,""
|
175 |
+
def order_data(self):
|
176 |
+
self.df[['text','speaker_id','secs','flag']]=self.data
|
177 |
+
self.df=self.df.sort_values(by=['flag'], ascending=False)
|
178 |
+
vv=self.settt(self.df)
|
179 |
+
return vv
|
180 |
+
def connect_drive(self):
|
181 |
+
from google.colab import drive
|
182 |
+
drive.mount('/content/drive')
|
183 |
+
def get_page_data(self, page_number):
|
184 |
+
start_index = page_number * 10
|
185 |
+
end_index = start_index + 10
|
186 |
+
return self.data.iloc[start_index:end_index]
|
187 |
+
def update_page(self, new_page):
|
188 |
+
self.current_page = new_page
|
189 |
+
return (
|
190 |
+
self.get_page_data(self.current_page),
|
191 |
+
self.current_page > 0,
|
192 |
+
self.current_page < len(self.data) // 10 - 1,
|
193 |
+
self.current_page
|
194 |
+
)
|
195 |
+
def clear_txt(self):
|
196 |
+
self.data['text'] =self.data['text'].apply(self.remove_hamza_from_alif_and_symbols)
|
197 |
+
return self.get_page_data(self.current_page)
|
198 |
+
def get_text_from_audio(self,audio):
|
199 |
+
if len(audio)!=0:
|
200 |
+
sf.write("temp.wav", audio, 16000,format='WAV')
|
201 |
+
|
202 |
+
client = Client("MohamedRashad/Arabic-Whisper-CodeSwitching-Edition")
|
203 |
+
result = client.predict(
|
204 |
+
inputs=handle_file('temp.wav'),
|
205 |
+
api_name="/predict_1"
|
206 |
+
)
|
207 |
+
return result
|
208 |
+
else:
|
209 |
+
return ""
|
210 |
+
|
211 |
+
def on_column_dropdown_change_operater(self,selected_column,selected_column1):
|
212 |
+
if selected_column1==">":
|
213 |
+
return self.data[self.data['secs'] > selected_column ]
|
214 |
+
elif selected_column1=="<":
|
215 |
+
return self.data[self.data['secs'] < selected_column]
|
216 |
+
elif selected_column1=="=":
|
217 |
+
return self.data[self.data['secs'] == selected_column]
|
218 |
+
else:
|
219 |
+
return self.data
|
220 |
+
# Perform actions based on the selected column
|
221 |
+
|
222 |
+
def on_column_dropdown_change(self,selected_column):
|
223 |
+
data=self.df
|
224 |
+
if selected_column=="all":
|
225 |
+
|
226 |
+
return self.set1(data),len(data)
|
227 |
+
elif selected_column=="0":
|
228 |
+
data=data[data['flag'] ==0]
|
229 |
+
return self.set1(data),len(data)
|
230 |
+
else :
|
231 |
+
data=data[data['flag'] ==1]
|
232 |
+
return self.set1(data),len(data)
|
233 |
+
|
234 |
+
def on_select(self,evt:gr.SelectData):
|
235 |
+
index_now = evt.index[0]
|
236 |
+
self.current_selected = (self.current_page * 10) + index_now
|
237 |
+
row = self.data.iloc[self.current_selected]
|
238 |
+
row_audio = self.sdata[self.current_selected]
|
239 |
+
self.speaker_id=row['speaker_id']
|
240 |
+
return (16000, row_audio), row['text']
|
241 |
+
def finsh_data(self):
|
242 |
+
self.df['audio'] = self.sdata
|
243 |
+
self.df[['text','speaker_id','secs','flag']]=self.data
|
244 |
+
|
245 |
+
return self.df
|
246 |
+
def All_enhance(self):
|
247 |
+
for i in range(0,len(self.sdata)):
|
248 |
+
_,y=remove_nn(self.sdata[i])
|
249 |
+
self.sdata[i]=y
|
250 |
+
return self.data
|
251 |
+
|
252 |
+
return self.get_page_data(self.current_page)
|
253 |
+
def get_output_audio(self):
|
254 |
+
return self.sdata[self.current_selected] if self.current_selected >= 0 else None
|
255 |
+
def Convert_DataFreme_To_DataSet(self,namedata):
|
256 |
+
df=self.df
|
257 |
+
|
258 |
+
df['audio'] = df['audio'].apply(lambda x: np.array(x, dtype=np.float32))
|
259 |
+
if "__index_level_0__" in df.columns:
|
260 |
+
df =df.drop(columns=["__index_level_0__"])
|
261 |
+
train_df =df
|
262 |
+
|
263 |
+
|
264 |
+
|
265 |
+
ds = {
|
266 |
+
"train": Dataset.from_pandas(train_df)
|
267 |
+
|
268 |
+
}
|
269 |
+
|
270 |
+
dataset = DatasetDict(ds)
|
271 |
+
dataset.push_to_hub(namedata,token=os.environ.get("auth_acess_data"),private=True)
|
272 |
+
return namedata
|
273 |
+
|
274 |
+
def delete_row(self):
|
275 |
+
if len(self.data)!=0 or self.current_selected != -1 :
|
276 |
+
self.data.drop(self.current_selected, inplace=True)
|
277 |
+
self.data.reset_index(drop=True, inplace=True)
|
278 |
+
self.df.drop(self.current_selected, inplace=True)
|
279 |
+
self.df.reset_index(drop=True, inplace=True)
|
280 |
+
self.sdata.pop(self.current_selected)
|
281 |
+
self.current_selected = -1
|
282 |
+
# self.audio_player.update(None) # Clear audio player
|
283 |
+
# self.txt_audio.update("") # Clear text input
|
284 |
+
|
285 |
+
return self.get_page_data(self.current_page),None,""
|
286 |
+
def login(self, token):
|
287 |
+
# Your actual login logic here (e.g., database check)
|
288 |
+
if token == os.environ.get("token_login") :
|
289 |
+
return gr.update(visible=False),gr.update(visible=True),True
|
290 |
+
else:
|
291 |
+
return gr.update(visible=True), gr.update(visible=False),None
|
292 |
+
def load_demo(self,sesion):
|
293 |
+
if sesion:
|
294 |
+
return gr.update(visible=False),gr.update(visible=True)
|
295 |
+
|
296 |
+
return gr.update(visible=True), gr.update(visible=False)
|
297 |
+
def start_tab1(self):
|
298 |
+
with gr.Blocks(theme=self.seafoam, css="""
|
299 |
+
table.svelte-82jkx.svelte-82jkx{
|
300 |
+
font-size: x-small;
|
301 |
+
}
|
302 |
+
.checkbox-group label {
|
303 |
+
background-color: #f0f0f5; /* لون خلفية فاتح */
|
304 |
+
padding: 10px;
|
305 |
+
border-radius: 5px; /* زوايا دائرية */
|
306 |
+
}
|
307 |
+
const textbox = document.querySelector('.txt_audio'); // تحديد المكون النصي
|
308 |
+
textbox.style.direction = 'ltr';
|
309 |
+
.checkbox-group input:checked + label {
|
310 |
+
background-color: #e0f0ff; /* لون خلفية عند التحديد */
|
311 |
+
font-weight: bold;
|
312 |
+
}
|
313 |
+
""") as demo:
|
314 |
+
sesion_state = gr.State()
|
315 |
+
|
316 |
+
with gr.Column(scale=1, min_width=200,visible=True) as login_panal: # Login panel
|
317 |
+
gr.Markdown("## auth acess page")
|
318 |
+
token_login = gr.Textbox(label="token")
|
319 |
+
|
320 |
+
login_button = gr.Button("Login")
|
321 |
+
with gr.Column(scale=1, visible=False) as main_panel:
|
322 |
+
with gr.Row(equal_height=False):
|
323 |
+
with gr.Tabs():
|
324 |
+
with gr.TabItem("Processing Data "):
|
325 |
+
self.data_Processing()
|
326 |
+
login_button.click(self.login, inputs=[token_login], outputs=[login_panal,main_panel,sesion_state])
|
327 |
+
demo.load(self.load_demo, [sesion_state], [login_panal,main_panel])
|
328 |
+
|
329 |
+
|
330 |
+
return demo
|
331 |
+
def create_Tabs(self): # fix: method was missing
|
332 |
+
#with gr.Blocks() as interface:
|
333 |
+
with gr.Tabs():
|
334 |
+
with gr.TabItem("Excel"):
|
335 |
+
with gr.Row():
|
336 |
+
txt_filepath_excel=gr.Text("NameFile")
|
337 |
+
txt_text_excel=gr.Text("Text" )
|
338 |
+
but_send_excel=gr.Button("Send",size="sm")
|
339 |
+
|
340 |
+
with gr.TabItem("CVC"):
|
341 |
+
with gr.Row():
|
342 |
+
txt_filepath_cvc=gr.Text("File")
|
343 |
+
txt_text_cvc=gr.Text("Text" )
|
344 |
+
but_send_cvc=gr.Button("Send",size="sm")
|
345 |
+
with gr.TabItem("DateSet"):
|
346 |
+
self.txt_filepath_dir=gr.Text(placeholder="link dir",interactive=True)
|
347 |
+
#self.txt_text=gr.Text("Text" )
|
348 |
+
self.but_send_dir=gr.Button("Send",size="sm")
|
349 |
+
with gr.TabItem("Dir"):
|
350 |
+
txt_filepath_dateSet=gr.Text("link DateSet")
|
351 |
+
#self.txt_text=gr.Text("Text" )
|
352 |
+
but_send_dateSet=gr.Button("Send",size="sm")
|
353 |
+
with gr.TabItem("Cut Video"):
|
354 |
+
self.txt_filepath_dateSet=gr.Text("رابط الفيديو",interactive=True)
|
355 |
+
self.num = gr.Number(label=" ادخل رقم طبيعي")
|
356 |
+
|
357 |
+
self.but_send_dateSet_cut=gr.Button("Send",size="sm")
|
358 |
+
|
359 |
+
def Convert_DataFrame_to_Bitch(self):
|
360 |
+
with gr.Row():
|
361 |
+
self.txt_output_dir=gr.Text("output Name dir",interactive=True)
|
362 |
+
self.txt_train_batch_size=gr.Text("train_batch_size",interactive=True)
|
363 |
+
self.txt_eval_batch_size=gr.Text("eval_batch_size",interactive=True )
|
364 |
+
self.but_convert_bitch=gr.Button("Convert Bitch",size="sm")
|
365 |
+
with gr.Row():
|
366 |
+
self.label_Bitch=gr.Label("Dir Output Bitch :")
|
367 |
+
|
368 |
+
|
369 |
+
def data_Processing(self):
|
370 |
+
|
371 |
+
#with gr.Column(scale=2,min_width=40):
|
372 |
+
|
373 |
+
#with gr.Row():
|
374 |
+
#with gr.Accordion("Open Data", open=False):
|
375 |
+
#with gr.Row():
|
376 |
+
# self.txt_filepath_dateSet=gr.Text("link DateSet",interactive=True)
|
377 |
+
#self.txt_text=gr.Text("Text" )
|
378 |
+
#self.but_send_dateSet=gr.Button("Send",size="sm")
|
379 |
+
|
380 |
+
|
381 |
+
with gr.Accordion("Install Data", open=False):
|
382 |
+
with gr.Row():
|
383 |
+
self.create_Tabs()
|
384 |
+
with gr.Row():
|
385 |
+
columns = []
|
386 |
+
columns1 = []
|
387 |
+
|
388 |
+
columns =["all","0","1"]
|
389 |
+
columns.append("all")
|
390 |
+
self.labell=gr.Label("count:")
|
391 |
+
self.column_dropdown = gr.Dropdown(choices=columns, label="speaker_id")
|
392 |
+
with gr.Row():
|
393 |
+
|
394 |
+
columns1=unique_speaker_ids =self.df['secs'].unique().tolist()
|
395 |
+
columns1.append("all")
|
396 |
+
self.column_dropdown1 = gr.Dropdown(choices=columns1 , label="secs")
|
397 |
+
|
398 |
+
self.column_dropdown11 = gr.Dropdown(choices=["all","<",">","="], label="operater")
|
399 |
+
|
400 |
+
|
401 |
+
with gr.Row():
|
402 |
+
|
403 |
+
|
404 |
+
with gr.Column(scale=5):
|
405 |
+
gr.Markdown("## Data Viewer")
|
406 |
+
#d=self.get_page_data(self.current_page)
|
407 |
+
# Correct the indentation here:
|
408 |
+
self.data_table = gr.DataFrame( # Notice 'self.' here
|
409 |
+
value=self.get_page_data(self.current_page),
|
410 |
+
headers=["Text","speaker_id"])
|
411 |
+
|
412 |
+
# interactive=True
|
413 |
+
|
414 |
+
#self.data_table1 = gr.DataFrame(headers=[ "Text","Id_spiker"])
|
415 |
+
with gr.Row(equal_height=False):
|
416 |
+
self.prev_button = gr.Button("<",scale=1, size="sm",min_width=30)
|
417 |
+
|
418 |
+
self.page_number = gr.Number(value=self.current_page + 1, label="Page",scale=1,min_width=100)
|
419 |
+
self.next_button = gr.Button(">",scale=1, size="sm",min_width=30)
|
420 |
+
|
421 |
+
with gr.Row(equal_height=False):
|
422 |
+
|
423 |
+
#inputs=gr.CheckboxGroup(["John", "Mary", "Peter", "Susan"])
|
424 |
+
self.but_cleartxt=gr.Button("clear Text",variant="primary",size="sm",min_width=30)
|
425 |
+
self.btn_all_enhance=gr.Button("All enhance",size="sm",variant="primary",min_width=30)
|
426 |
+
self.btn_ClearEnglish=gr.Button("ClearEnglish",size="sm",variant="primary",min_width=30)
|
427 |
+
|
428 |
+
|
429 |
+
|
430 |
+
|
431 |
+
|
432 |
+
|
433 |
+
|
434 |
+
|
435 |
+
|
436 |
+
|
437 |
+
with gr.Column(scale=4):
|
438 |
+
gr.Markdown("## Row Data")
|
439 |
+
self.txt_audio = gr.Textbox(label="Text", interactive=True,rtl=True)
|
440 |
+
with gr.Row(equal_height=False):
|
441 |
+
self.audio_player = gr.Audio(label="Audio")
|
442 |
+
with gr.Row(equal_height=False):
|
443 |
+
self.btn_del = gr.Button("Delete ", size="sm",variant="primary",min_width=50)
|
444 |
+
self.btn_save = gr.Button("Save", size="sm",variant="primary",min_width=50)
|
445 |
+
self.totext=gr.Button("to text",size="sm" ,variant="primary",min_width=50)
|
446 |
+
|
447 |
+
# with gr.Row(equal_height=False):
|
448 |
+
|
449 |
+
|
450 |
+
with gr.Row(equal_height=False):
|
451 |
+
self.btn_newsave=gr.Button("New Save Cut",size="sm",variant="primary",min_width=50)
|
452 |
+
self.btn_enhance = gr.Button("enhance ", size="sm",variant="primary",min_width=50)
|
453 |
+
self.order= gr.Button("order ", size="sm",variant="primary",min_width=50)
|
454 |
+
|
455 |
+
|
456 |
+
with gr.Row(equal_height=False,variant="heading-1"):
|
457 |
+
with gr.Accordion("Save Bitch", open=False):
|
458 |
+
|
459 |
+
self.txt_dataset=gr.Text("save dataset",interactive=True)
|
460 |
+
self.btn_convertDataset=gr.Button("Dir Output Bitch :",variant="primary")
|
461 |
+
self.label_dataset=gr.Label("count:")
|
462 |
+
self.order.click(self.order_data,[],[self.data_table])
|
463 |
+
self.btn_ClearEnglish.click(self.clearenglish,[],[self.data_table])
|
464 |
+
self.but_send_dir.click(self.getdataset, [self.txt_filepath_dir],[self.data_table,self.labell,self.txt_dataset])
|
465 |
+
#self.but_send_dateSet_cut.click(self.splitt, [self.txt_filepath_dateSet,self.num],[self.data_table,self.labell])
|
466 |
+
#self.txt_audio.Style(container=False, css=".txt_audio { direction: rtl; }")
|
467 |
+
#self.but_send_dateSet.click(self.Read_DataSet, [self.txt_filepath_dateSet],[self.data_table ])
|
468 |
+
self.data_table.select(self.on_select, None, [self.audio_player, self.txt_audio])
|
469 |
+
self.prev_button.click(lambda page: self.update_page(page - 1), [self.page_number], [self.data_table, self.prev_button, self.next_button, self.page_number])
|
470 |
+
#self.btn_save.click(self.save_row, [self.txt_audio,self.audio_player], [self.data_table])
|
471 |
+
self.next_button.click(lambda page: self.update_page(page + 1), [self.page_number], [self.data_table, self.prev_button, self.next_button, self.page_number])
|
472 |
+
self.column_dropdown.change(self.on_column_dropdown_change,[self.column_dropdown], [self.data_table,self.labell])
|
473 |
+
self.column_dropdown11.change(self.on_column_dropdown_change_operater,[self.column_dropdown1,self.column_dropdown11], [self.data_table])
|
474 |
+
self.btn_convertDataset.click(self.Convert_DataFreme_To_DataSet,[self.txt_dataset],[self.label_dataset])
|
475 |
+
self.totext.click(lambda:self.get_text_from_audio(self.get_output_audio()), [], self.txt_audio)
|
476 |
+
self.btn_newsave.click(self.trim_audio,[self.txt_audio,self.audio_player],[self.data_table,self.audio_player,self.txt_audio])
|
477 |
+
self.btn_save.click(self.save_row, [self.txt_audio,self.audio_player], [self.data_table,self.audio_player,self.txt_audio])
|
478 |
+
#self.btn_save.click(self.save_row, [self.txt_audio,self.audio_player], [self.data_table])
|
479 |
+
self.btn_all_enhance.click(self.All_enhance,[],[self.data_table])
|
480 |
+
#self.btn_enhance.click(remove_nn, [self.audio_player], [self.audio_player])
|
481 |
+
self.but_cleartxt.click(self.clear_txt,[],[self.data_table])
|
482 |
+
self.btn_del.click(self.delete_row,[], [self.data_table,self.audio_player,self.txt_audio])
|
483 |
+
self.btn_enhance.click(lambda: remove_nn(self.get_output_audio()), [], self.audio_player)
|
484 |
+
#self.column_dropdown.change(lambda selected_column:self.settt(self.on_column_dropdown_change(selected_column)), [self.column_dropdown], [self.data_table])
|
485 |
+
#self.column_dropdown.change(lambda selected_column:self.settt(x.on_column_dropdown_change(selected_column)), [x.column_dropdown], [self.data_table])
|
486 |
+
#self.btn_denoise.click(self.remove_nn, [self.audio_player], [self.audio_player])
|
487 |
+
|
488 |
+
|
489 |
+
|
490 |
+
dff=pd.DataFrame(columns=['text', 'audio', 'samplerate', 'secs', 'speaker_id', '_speaker_id','flag'])
|
491 |
+
app=DataViewerApp(dff)
|
492 |
+
s=app.start_tab1()
|
493 |
+
s.launch()
|