Spaces:
Sleeping
Sleeping
Commit
·
376f45a
1
Parent(s):
0c913ef
improved csv handling
Browse files
app.py
CHANGED
@@ -214,20 +214,24 @@ def getBeatsv2(audio:gr.Audio):
|
|
214 |
fig = plotBeattimes(times_label_one, audiodata, sr, times_label_zero)
|
215 |
|
216 |
|
217 |
-
|
218 |
|
219 |
|
220 |
return fig, featuredf.to_markdown(), (sr, audiodata)
|
221 |
|
222 |
-
def updateBeatsv2(
|
223 |
-
|
224 |
-
df = mdpd.from_md(df)
|
225 |
|
226 |
sr, audiodata = getaudiodata(audio)
|
227 |
|
228 |
|
229 |
if uploadeddf != None:
|
230 |
-
beattimes_table = pd.read_csv(
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
|
232 |
s1_times = beattimes_table[beattimes_table["Label (S1=0/S2=1)"] == 0]["Beattimes"].to_numpy()
|
233 |
s2_times = beattimes_table[beattimes_table["Label (S1=0/S2=1)"] == 1]["Beattimes"].to_numpy()
|
@@ -236,16 +240,24 @@ def updateBeatsv2(beattimes_table:gr.Markdown, audio:gr.Audio, uploadeddf:gr.Fil
|
|
236 |
|
237 |
return fig, beattimes_table.to_markdown()
|
238 |
|
239 |
-
def download_df (
|
240 |
|
241 |
-
df = mdpd.from_md(
|
|
|
|
|
242 |
|
243 |
-
print(df)
|
244 |
|
245 |
temp_dir = tempfile.gettempdir()
|
246 |
-
temp_path = os.path.join(temp_dir, "
|
247 |
|
248 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
|
250 |
return temp_path
|
251 |
|
@@ -291,7 +303,7 @@ with gr.Blocks() as app:
|
|
291 |
|
292 |
csv_download.click(download_df, inputs=[beattimes_table], outputs=[csv_download])
|
293 |
getBeatsbtn.click(getBeatsv2, inputs=audiofile, outputs=[beats_wave_plot, beattimes_table, cleanedaudio])
|
294 |
-
updateBeatsbtn.click(updateBeatsv2, inputs=[
|
295 |
|
296 |
gr.Examples(
|
297 |
examples=example_files,
|
|
|
214 |
fig = plotBeattimes(times_label_one, audiodata, sr, times_label_zero)
|
215 |
|
216 |
|
217 |
+
featuredf = featuredf.drop(columns=["S1 to S2", "S2 to S1"])
|
218 |
|
219 |
|
220 |
return fig, featuredf.to_markdown(), (sr, audiodata)
|
221 |
|
222 |
+
def updateBeatsv2(audio:gr.Audio, uploadeddf:gr.File=None)-> go.Figure:
|
|
|
|
|
223 |
|
224 |
sr, audiodata = getaudiodata(audio)
|
225 |
|
226 |
|
227 |
if uploadeddf != None:
|
228 |
+
beattimes_table = pd.read_csv(
|
229 |
+
filepath_or_buffer=uploadeddf,
|
230 |
+
sep=";",
|
231 |
+
decimal=",",
|
232 |
+
encoding="utf-8-sig")
|
233 |
+
else:
|
234 |
+
raise FileNotFoundError("No file uploaded")
|
235 |
|
236 |
s1_times = beattimes_table[beattimes_table["Label (S1=0/S2=1)"] == 0]["Beattimes"].to_numpy()
|
237 |
s2_times = beattimes_table[beattimes_table["Label (S1=0/S2=1)"] == 1]["Beattimes"].to_numpy()
|
|
|
240 |
|
241 |
return fig, beattimes_table.to_markdown()
|
242 |
|
243 |
+
def download_df (beattimes_table: str):
|
244 |
|
245 |
+
df = mdpd.from_md(beattimes_table)
|
246 |
+
df['Beattimes'] = df['Beattimes'].astype(float)
|
247 |
+
df['Label (S1=0/S2=1)'] = df['Label (S1=0/S2=1)'].astype(int)
|
248 |
|
|
|
249 |
|
250 |
temp_dir = tempfile.gettempdir()
|
251 |
+
temp_path = os.path.join(temp_dir, "beattimes.csv")
|
252 |
|
253 |
+
|
254 |
+
df.to_csv(
|
255 |
+
index=False,
|
256 |
+
columns=["Beattimes", "Label (S1=0/S2=1)"],
|
257 |
+
path_or_buf=temp_path,
|
258 |
+
sep=";",
|
259 |
+
decimal=",",
|
260 |
+
encoding="utf-8-sig")
|
261 |
|
262 |
return temp_path
|
263 |
|
|
|
303 |
|
304 |
csv_download.click(download_df, inputs=[beattimes_table], outputs=[csv_download])
|
305 |
getBeatsbtn.click(getBeatsv2, inputs=audiofile, outputs=[beats_wave_plot, beattimes_table, cleanedaudio])
|
306 |
+
updateBeatsbtn.click(updateBeatsv2, inputs=[audiofile, uploadDF], outputs=[beats_wave_plot, beattimes_table])
|
307 |
|
308 |
gr.Examples(
|
309 |
examples=example_files,
|