Spaces:
Sleeping
Sleeping
OthmaneLKH
commited on
Commit
•
9023283
1
Parent(s):
0ca0215
Update app.py
Browse files
app.py
CHANGED
@@ -418,70 +418,36 @@ def anonymization_with_fn(selected_sentences, query):
|
|
418 |
identified_words_output_df: gr.update(value=identified_df, visible=False),
|
419 |
}
|
420 |
|
|
|
|
|
421 |
|
422 |
-
|
|
|
|
|
|
|
423 |
|
424 |
-
|
|
|
|
|
|
|
425 |
|
426 |
-
if not (KEYS_DIR / f"{USER_ID}/evaluation_key").is_file():
|
427 |
-
error_message = "Error ❌: Please generate the key first!"
|
428 |
-
return {chatgpt_response_anonymized: gr.update(value=error_message)}
|
429 |
-
|
430 |
-
if not (CLIENT_DIR / f"{USER_ID}_encrypted_output").is_file():
|
431 |
-
error_message = "Error ❌: Please encrypt your query first!"
|
432 |
-
return {chatgpt_response_anonymized: gr.update(value=error_message)}
|
433 |
-
|
434 |
-
context_prompt = read_txt(PROMPT_PATH)
|
435 |
-
|
436 |
-
# Prepare prompt
|
437 |
-
query = (
|
438 |
-
"Document content:\n```\n"
|
439 |
-
+ anonymized_document
|
440 |
-
+ "\n\n```"
|
441 |
-
+ "Query:\n```\n"
|
442 |
-
+ anonymized_query
|
443 |
-
+ "\n```"
|
444 |
-
)
|
445 |
-
print(f'Prompt of CHATGPT:\n{query}')
|
446 |
-
|
447 |
-
completion = client.chat.completions.create(
|
448 |
-
model="gpt-4-1106-preview", # Replace with "gpt-4" if available
|
449 |
-
messages=[
|
450 |
-
{"role": "system", "content": context_prompt},
|
451 |
-
{"role": "user", "content": query},
|
452 |
-
],
|
453 |
-
)
|
454 |
-
anonymized_response = completion.choices[0].message.content
|
455 |
-
uuid_map = read_json(MAPPING_UUID_PATH)
|
456 |
-
|
457 |
-
inverse_uuid_map = {
|
458 |
-
v: k for k, v in uuid_map.items()
|
459 |
-
} # TODO load the inverse mapping from disk for efficiency
|
460 |
-
|
461 |
-
# Pattern to identify words and non-words (including punctuation, spaces, etc.)
|
462 |
-
tokens = re.findall(r"(\b[\w\.\/\-@]+\b|[\s,.!?;:'\"-]+)", anonymized_response)
|
463 |
-
processed_tokens = []
|
464 |
-
|
465 |
-
for token in tokens:
|
466 |
-
# Directly append non-word tokens or whitespace to processed_tokens
|
467 |
-
if not token.strip() or not re.match(r"\w+", token):
|
468 |
-
processed_tokens.append(token)
|
469 |
-
continue
|
470 |
-
|
471 |
-
if token in inverse_uuid_map:
|
472 |
-
processed_tokens.append(inverse_uuid_map[token])
|
473 |
-
else:
|
474 |
-
processed_tokens.append(token)
|
475 |
-
deanonymized_response = "".join(processed_tokens)
|
476 |
-
|
477 |
-
return {chatgpt_response_anonymized: gr.update(value=anonymized_response),
|
478 |
-
chatgpt_response_deanonymized: gr.update(value=deanonymized_response)}
|
479 |
|
480 |
|
481 |
demo = gr.Blocks(css=".markdown-body { font-size: 18px; }")
|
482 |
|
483 |
with demo:
|
484 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
485 |
gr.Markdown(
|
486 |
"""
|
487 |
<p align="center">
|
|
|
418 |
identified_words_output_df: gr.update(value=identified_df, visible=False),
|
419 |
}
|
420 |
|
421 |
+
# Define the folder path containing audio files
|
422 |
+
AUDIO_FOLDER_PATH = "./files/"
|
423 |
|
424 |
+
# Function to list available audio files in the folder
|
425 |
+
def get_audio_files():
|
426 |
+
files = [f for f in os.listdir(AUDIO_FOLDER_PATH) if f.endswith(('.wav', '.mp3'))]
|
427 |
+
return files
|
428 |
|
429 |
+
# Step 1: Load and display audio file
|
430 |
+
def load_audio_file(selected_audio):
|
431 |
+
file_path = os.path.join(AUDIO_FOLDER_PATH, selected_audio)
|
432 |
+
return file_path
|
433 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
434 |
|
435 |
|
436 |
demo = gr.Blocks(css=".markdown-body { font-size: 18px; }")
|
437 |
|
438 |
with demo:
|
439 |
|
440 |
+
# Step 1: Add an audio file
|
441 |
+
gr.Markdown("## Step 1: Add an Audio File")
|
442 |
+
audio_files = get_audio_files()
|
443 |
+
|
444 |
+
with gr.Row():
|
445 |
+
audio_file_dropdown = gr.Dropdown(audio_files, label="Select an Audio File", interactive=True)
|
446 |
+
audio_output = gr.Audio(label="Selected Audio", type="filepath")
|
447 |
+
|
448 |
+
# When an audio file is selected, it will display the file path
|
449 |
+
audio_file_dropdown.change(fn=load_audio_file, inputs=[audio_file_dropdown], outputs=[audio_output])
|
450 |
+
|
451 |
gr.Markdown(
|
452 |
"""
|
453 |
<p align="center">
|