MeysamSh commited on
Commit
d562907
·
1 Parent(s): 50509cd

Add application file first version

Browse files
Files changed (1) hide show
  1. app.py +57 -3
app.py CHANGED
@@ -1,8 +1,62 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
  demo.launch()
8
 
 
1
  import gradio as gr
2
+ import pandas as pd
3
+ import os
4
 
5
+ # Folder with your audio files
6
+ AUDIO_FOLDER = "audio_files"
7
+ audio_files = sorted(os.listdir(AUDIO_FOLDER))
8
+ current_index = 0
9
+
10
+ # CSV to store annotations
11
+ ANNOTATION_FILE = "annotations.csv"
12
+ if not os.path.exists(ANNOTATION_FILE):
13
+ df = pd.DataFrame(columns=["user_id", "gender", "audio_file", "score"])
14
+ df.to_csv(ANNOTATION_FILE, index=False)
15
+
16
+ # Function to save annotation
17
+ def save_annotation(user_id, gender, score):
18
+ global current_index
19
+ if current_index >= len(audio_files):
20
+ return "No more audio files.", None
21
+
22
+ audio_file = audio_files[current_index]
23
+
24
+ # Save to CSV
25
+ df = pd.read_csv(ANNOTATION_FILE)
26
+ df = pd.concat([df, pd.DataFrame([{
27
+ "user_id": user_id,
28
+ "gender": gender,
29
+ "audio_file": audio_file,
30
+ "score": score
31
+ }])], ignore_index=True)
32
+ df.to_csv(ANNOTATION_FILE, index=False)
33
+
34
+ current_index += 1
35
+ if current_index < len(audio_files):
36
+ next_audio = os.path.join(AUDIO_FOLDER, audio_files[current_index])
37
+ else:
38
+ next_audio = None
39
+
40
+ return "Saved! Next audio loaded." if next_audio else "All audios completed.", next_audio
41
+
42
+ # Gradio interface
43
+ with gr.Blocks() as demo:
44
+ with gr.Row():
45
+ user_id = gr.Textbox(label="User ID")
46
+ gender = gr.Dropdown(label="Gender", choices=["Male", "Female", "Other"])
47
+ audio_player = gr.Audio(label="Audio File", source="upload", type="filepath")
48
+ score = gr.Slider(label="MOS Score (1-5)", minimum=1, maximum=5, step=1)
49
+ submit_btn = gr.Button("Submit Score")
50
+ status = gr.Textbox(label="Status")
51
+
52
+ submit_btn.click(
53
+ fn=save_annotation,
54
+ inputs=[user_id, gender, score],
55
+ outputs=[status, audio_player]
56
+ )
57
+
58
+ # Load first audio
59
+ audio_player.value = os.path.join(AUDIO_FOLDER, audio_files[current_index])
60
 
 
61
  demo.launch()
62