Spaces:
Sleeping
Sleeping
Ali Sartaz Khan
commited on
Commit
·
cc08a1c
1
Parent(s):
96905d6
update
Browse files
talk_arena/__pycache__/audio_collection.cpython-312.pyc
CHANGED
Binary files a/talk_arena/__pycache__/audio_collection.cpython-312.pyc and b/talk_arena/__pycache__/audio_collection.cpython-312.pyc differ
|
|
talk_arena/audio_collection.py
CHANGED
@@ -18,16 +18,21 @@ os.makedirs("outputs", exist_ok=True)
|
|
18 |
# Initialize Hugging Face API client
|
19 |
hf_api = HfApi(token=os.getenv("HF_TOKEN"))
|
20 |
DATASET_REPO = "alisartazkhan/audioLLM_judge"
|
21 |
-
CATEGORY = "
|
22 |
MAX_RECORDINGS = 5 # Number of prompts to record
|
23 |
COMPLETION_CODE = "CEO4RWQ6"
|
24 |
resampler = Audio(sampling_rate=16_000)
|
25 |
|
26 |
-
#
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
# Create a JSON database to track uploads
|
33 |
class UploadTracker:
|
@@ -44,10 +49,10 @@ class UploadTracker:
|
|
44 |
with open(filename, "r") as f:
|
45 |
self.data = json.load(f)
|
46 |
|
47 |
-
def add_recording(self,
|
48 |
"""Add a record of an uploaded recording"""
|
49 |
record = {
|
50 |
-
"
|
51 |
"audio_hash": audio_hash,
|
52 |
"filename": filename,
|
53 |
"timestamp": str(uuid.uuid4())
|
@@ -98,17 +103,17 @@ def upload_to_hf(local_path, repo_path):
|
|
98 |
print(f"Error uploading file to HF: {e}")
|
99 |
return False
|
100 |
|
101 |
-
def on_submit(audio_input,
|
102 |
"""Handle the submission of a recorded audio prompt"""
|
103 |
if audio_input is None:
|
104 |
return (
|
105 |
-
gr.Markdown(f"# Recording {
|
106 |
-
gr.Markdown(
|
107 |
-
gr.Markdown(f"### \"{
|
108 |
gr.Audio(value=None, label="Record your response"),
|
109 |
gr.Button("Submit Recording", interactive=False),
|
110 |
-
gr.Button("Next
|
111 |
-
|
112 |
)
|
113 |
|
114 |
# Process the audio
|
@@ -123,67 +128,57 @@ def on_submit(audio_input, prompt_index):
|
|
123 |
|
124 |
# Create unique filename
|
125 |
unique_id = str(uuid.uuid4())[:8]
|
126 |
-
|
|
|
127 |
|
128 |
# Save the original (non-resampled) audio
|
129 |
sf.write(local_filename, y, sr, format="wav")
|
130 |
|
131 |
# Upload to HF dataset
|
132 |
-
hf_path = f"{CATEGORY}/
|
133 |
upload_to_hf(local_filename, hf_path)
|
134 |
|
135 |
# Add to tracker
|
136 |
-
tracker.add_recording(
|
137 |
|
138 |
# Show success message
|
139 |
return (
|
140 |
-
gr.Markdown(f"# Recording {
|
141 |
-
gr.Markdown(
|
142 |
-
gr.Markdown(f"###
|
143 |
gr.Audio(value=None, label="Record your response"),
|
144 |
gr.Button("Submit Recording", interactive=False),
|
145 |
-
gr.Button("Next
|
146 |
-
|
147 |
)
|
148 |
|
149 |
-
def next_prompt(
|
150 |
"""Move to the next prompt"""
|
151 |
-
|
152 |
|
153 |
# Check if we've gone through all prompts
|
154 |
-
if
|
155 |
return (
|
156 |
gr.Markdown(f"# All recordings complete! Completion code: {COMPLETION_CODE}"),
|
157 |
gr.Markdown("## Thank you for your participation."),
|
158 |
-
gr.Markdown("### You have completed all
|
159 |
gr.Audio(visible=False),
|
160 |
gr.Button(visible=False),
|
161 |
gr.Button(visible=False),
|
162 |
-
|
163 |
)
|
164 |
|
165 |
-
# Display the next
|
166 |
return (
|
167 |
-
gr.Markdown(f"# Recording {
|
168 |
-
gr.Markdown(
|
169 |
-
gr.Markdown(f"### \"{
|
170 |
gr.Audio(value=None, label="Record your response", sources=["microphone"]),
|
171 |
gr.Button("Submit Recording", interactive=False),
|
172 |
-
gr.Button("Next
|
173 |
-
|
174 |
)
|
175 |
|
176 |
-
def submit_and_next(audio_input, prompt_index):
|
177 |
-
"""Handle submission and move to next prompt immediately"""
|
178 |
-
if audio_input is None:
|
179 |
-
return on_submit(audio_input, prompt_index)
|
180 |
-
|
181 |
-
# Call submission logic
|
182 |
-
_ = on_submit(audio_input, prompt_index)
|
183 |
-
|
184 |
-
# Then move to next prompt
|
185 |
-
return next_prompt(prompt_index)
|
186 |
-
|
187 |
def enable_submit_button(audio_input):
|
188 |
"""Enable the submit button when audio is recorded"""
|
189 |
if audio_input is not None:
|
@@ -199,11 +194,11 @@ theme = gr.themes.Soft(
|
|
199 |
|
200 |
# Create Gradio interface
|
201 |
with gr.Blocks(theme=theme, css="footer {visibility: hidden}") as demo:
|
202 |
-
|
203 |
|
204 |
title = gr.Markdown(f"# Recording 1/{MAX_RECORDINGS}")
|
205 |
-
instructions = gr.Markdown(
|
206 |
-
prompt_text = gr.Markdown(f"### \"{
|
207 |
|
208 |
audio_input = gr.Audio(
|
209 |
label="Record your response",
|
@@ -213,7 +208,7 @@ with gr.Blocks(theme=theme, css="footer {visibility: hidden}") as demo:
|
|
213 |
|
214 |
with gr.Row():
|
215 |
submit_btn = gr.Button("Submit Recording", interactive=False)
|
216 |
-
next_btn = gr.Button("Next
|
217 |
|
218 |
# Enable submit button when audio is recorded
|
219 |
audio_input.change(
|
@@ -224,25 +219,18 @@ with gr.Blocks(theme=theme, css="footer {visibility: hidden}") as demo:
|
|
224 |
|
225 |
# Handle submission
|
226 |
submit_btn.click(
|
227 |
-
fn=
|
228 |
-
inputs=[audio_input,
|
229 |
-
outputs=[title, instructions, prompt_text, audio_input, submit_btn, next_btn,
|
230 |
)
|
231 |
-
|
232 |
|
233 |
# Handle next button
|
234 |
next_btn.click(
|
235 |
fn=next_prompt,
|
236 |
-
inputs=[
|
237 |
-
outputs=[title, instructions, prompt_text, audio_input, submit_btn, next_btn,
|
238 |
)
|
239 |
|
240 |
# Launch the app
|
241 |
if __name__ == "__main__":
|
242 |
-
# First, create the prompts.json file
|
243 |
-
with open("talkarena/prompts.json", "w") as f:
|
244 |
-
json.dump({
|
245 |
-
"prompts": PROMPTS
|
246 |
-
}, f, indent=2)
|
247 |
-
|
248 |
demo.launch(share=True)
|
|
|
18 |
# Initialize Hugging Face API client
|
19 |
hf_api = HfApi(token=os.getenv("HF_TOKEN"))
|
20 |
DATASET_REPO = "alisartazkhan/audioLLM_judge"
|
21 |
+
CATEGORY = "pilot_tempo_control6"
|
22 |
MAX_RECORDINGS = 5 # Number of prompts to record
|
23 |
COMPLETION_CODE = "CEO4RWQ6"
|
24 |
resampler = Audio(sampling_rate=16_000)
|
25 |
|
26 |
+
# ====== MODIFY THIS SECTION TO CHANGE INSTRUCTIONS AND PROMPT ======
|
27 |
+
# Instructions for the user
|
28 |
+
USER_INSTRUCTIONS = """
|
29 |
+
## Recording Instructions:
|
30 |
+
Please record yourself reading your instruction clearly and naturally, speaking into the microphone in a quiet environment.
|
31 |
+
"""
|
32 |
+
|
33 |
+
# The prompt that users will record
|
34 |
+
RECORDING_PROMPT = ""
|
35 |
+
# ================================================================
|
36 |
|
37 |
# Create a JSON database to track uploads
|
38 |
class UploadTracker:
|
|
|
49 |
with open(filename, "r") as f:
|
50 |
self.data = json.load(f)
|
51 |
|
52 |
+
def add_recording(self, audio_hash, filename):
|
53 |
"""Add a record of an uploaded recording"""
|
54 |
record = {
|
55 |
+
"prompt": RECORDING_PROMPT,
|
56 |
"audio_hash": audio_hash,
|
57 |
"filename": filename,
|
58 |
"timestamp": str(uuid.uuid4())
|
|
|
103 |
print(f"Error uploading file to HF: {e}")
|
104 |
return False
|
105 |
|
106 |
+
def on_submit(audio_input, recording_count):
|
107 |
"""Handle the submission of a recorded audio prompt"""
|
108 |
if audio_input is None:
|
109 |
return (
|
110 |
+
gr.Markdown(f"# Recording {recording_count + 1}/{MAX_RECORDINGS}"),
|
111 |
+
gr.Markdown(USER_INSTRUCTIONS),
|
112 |
+
gr.Markdown(f"### \"{RECORDING_PROMPT}\""),
|
113 |
gr.Audio(value=None, label="Record your response"),
|
114 |
gr.Button("Submit Recording", interactive=False),
|
115 |
+
gr.Button("Next Recording", visible=False),
|
116 |
+
recording_count
|
117 |
)
|
118 |
|
119 |
# Process the audio
|
|
|
128 |
|
129 |
# Create unique filename
|
130 |
unique_id = str(uuid.uuid4())[:8]
|
131 |
+
clean_prompt = RECORDING_PROMPT.replace(" ", "_").replace(".", "").replace(",", "")[:20]
|
132 |
+
local_filename = f"outputs/{clean_prompt}_{audio_hash}_{unique_id}.wav"
|
133 |
|
134 |
# Save the original (non-resampled) audio
|
135 |
sf.write(local_filename, y, sr, format="wav")
|
136 |
|
137 |
# Upload to HF dataset
|
138 |
+
hf_path = f"{CATEGORY}/{clean_prompt}_{audio_hash}_{unique_id}.wav"
|
139 |
upload_to_hf(local_filename, hf_path)
|
140 |
|
141 |
# Add to tracker
|
142 |
+
tracker.add_recording(audio_hash, hf_path)
|
143 |
|
144 |
# Show success message
|
145 |
return (
|
146 |
+
gr.Markdown(f"# Recording {recording_count + 1}/{MAX_RECORDINGS}"),
|
147 |
+
gr.Markdown(USER_INSTRUCTIONS),
|
148 |
+
gr.Markdown(f"### Recording successfully uploaded!"),
|
149 |
gr.Audio(value=None, label="Record your response"),
|
150 |
gr.Button("Submit Recording", interactive=False),
|
151 |
+
gr.Button("Next Recording", visible=True),
|
152 |
+
recording_count
|
153 |
)
|
154 |
|
155 |
+
def next_prompt(recording_count):
|
156 |
"""Move to the next prompt"""
|
157 |
+
recording_count += 1
|
158 |
|
159 |
# Check if we've gone through all prompts
|
160 |
+
if recording_count >= MAX_RECORDINGS:
|
161 |
return (
|
162 |
gr.Markdown(f"# All recordings complete! Completion code: {COMPLETION_CODE}"),
|
163 |
gr.Markdown("## Thank you for your participation."),
|
164 |
+
gr.Markdown("### You have completed all recordings."),
|
165 |
gr.Audio(visible=False),
|
166 |
gr.Button(visible=False),
|
167 |
gr.Button(visible=False),
|
168 |
+
recording_count
|
169 |
)
|
170 |
|
171 |
+
# Display the next recording screen
|
172 |
return (
|
173 |
+
gr.Markdown(f"# Recording {recording_count + 1}/{MAX_RECORDINGS}"),
|
174 |
+
gr.Markdown(USER_INSTRUCTIONS),
|
175 |
+
gr.Markdown(f"### \"{RECORDING_PROMPT}\""),
|
176 |
gr.Audio(value=None, label="Record your response", sources=["microphone"]),
|
177 |
gr.Button("Submit Recording", interactive=False),
|
178 |
+
gr.Button("Next Recording", visible=False),
|
179 |
+
recording_count
|
180 |
)
|
181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
def enable_submit_button(audio_input):
|
183 |
"""Enable the submit button when audio is recorded"""
|
184 |
if audio_input is not None:
|
|
|
194 |
|
195 |
# Create Gradio interface
|
196 |
with gr.Blocks(theme=theme, css="footer {visibility: hidden}") as demo:
|
197 |
+
recording_count = gr.State(0)
|
198 |
|
199 |
title = gr.Markdown(f"# Recording 1/{MAX_RECORDINGS}")
|
200 |
+
instructions = gr.Markdown(USER_INSTRUCTIONS)
|
201 |
+
prompt_text = gr.Markdown(f"### \"{RECORDING_PROMPT}\"")
|
202 |
|
203 |
audio_input = gr.Audio(
|
204 |
label="Record your response",
|
|
|
208 |
|
209 |
with gr.Row():
|
210 |
submit_btn = gr.Button("Submit Recording", interactive=False)
|
211 |
+
next_btn = gr.Button("Next Recording", visible=False)
|
212 |
|
213 |
# Enable submit button when audio is recorded
|
214 |
audio_input.change(
|
|
|
219 |
|
220 |
# Handle submission
|
221 |
submit_btn.click(
|
222 |
+
fn=on_submit,
|
223 |
+
inputs=[audio_input, recording_count],
|
224 |
+
outputs=[title, instructions, prompt_text, audio_input, submit_btn, next_btn, recording_count]
|
225 |
)
|
|
|
226 |
|
227 |
# Handle next button
|
228 |
next_btn.click(
|
229 |
fn=next_prompt,
|
230 |
+
inputs=[recording_count],
|
231 |
+
outputs=[title, instructions, prompt_text, audio_input, submit_btn, next_btn, recording_count]
|
232 |
)
|
233 |
|
234 |
# Launch the app
|
235 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
demo.launch(share=True)
|