Spaces:
Running
Running
eaysu
commited on
Commit
·
a2d8dd2
1
Parent(s):
e70c4a6
update: interface
Browse files
app.py
CHANGED
|
@@ -12,6 +12,10 @@ def analyze_voice_similarity(audio_file1, audio_file2, progress=gr.Progress()):
|
|
| 12 |
# Update progress for visual feedback
|
| 13 |
progress(0, desc="Starting analysis...")
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
start_time = time.time() # Record start time
|
| 16 |
|
| 17 |
# Get current process information
|
|
@@ -25,7 +29,7 @@ def analyze_voice_similarity(audio_file1, audio_file2, progress=gr.Progress()):
|
|
| 25 |
progress(0.4, desc="Processing second audio file...")
|
| 26 |
wav2 = preprocess_wav(audio_file2)
|
| 27 |
except Exception as e:
|
| 28 |
-
return
|
| 29 |
|
| 30 |
# Extract speaker embeddings
|
| 31 |
progress(0.6, desc="Extracting voice embeddings...")
|
|
@@ -47,13 +51,40 @@ def analyze_voice_similarity(audio_file1, audio_file2, progress=gr.Progress()):
|
|
| 47 |
|
| 48 |
progress(1.0, desc="Analysis complete!")
|
| 49 |
|
| 50 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
return (
|
| 52 |
f"{similarity:.4f}",
|
| 53 |
-
result,
|
| 54 |
-
f"{memory_usage:.2f} MB",
|
| 55 |
f"{execution_time:.4f} seconds",
|
| 56 |
-
True,
|
| 57 |
"" # No error
|
| 58 |
)
|
| 59 |
|
|
@@ -71,24 +102,21 @@ with gr.Blocks(title="Voice Similarity Analyzer", theme=gr.themes.Soft()) as dem
|
|
| 71 |
analyze_button = gr.Button("Analyze Voice Similarity", variant="primary")
|
| 72 |
|
| 73 |
# Error message display
|
| 74 |
-
error_message = gr.Markdown(visible=
|
| 75 |
|
| 76 |
-
# Results display section
|
| 77 |
-
with gr.
|
| 78 |
-
gr.Markdown("##
|
| 79 |
-
|
| 80 |
with gr.Row():
|
| 81 |
with gr.Column():
|
| 82 |
-
similarity_display = gr.Textbox(label="Similarity Score")
|
| 83 |
with gr.Column():
|
| 84 |
-
conclusion_display = gr.Textbox(label="Conclusion")
|
| 85 |
-
|
| 86 |
-
gr.Markdown("### Performance Metrics")
|
| 87 |
with gr.Row():
|
| 88 |
with gr.Column():
|
| 89 |
-
memory_display = gr.Textbox(label="Memory Usage")
|
| 90 |
with gr.Column():
|
| 91 |
-
time_display = gr.Textbox(label="Execution Time")
|
| 92 |
|
| 93 |
# Handler for the analyze button
|
| 94 |
analyze_button.click(
|
|
@@ -99,7 +127,6 @@ with gr.Blocks(title="Voice Similarity Analyzer", theme=gr.themes.Soft()) as dem
|
|
| 99 |
conclusion_display,
|
| 100 |
memory_display,
|
| 101 |
time_display,
|
| 102 |
-
results_container,
|
| 103 |
error_message
|
| 104 |
]
|
| 105 |
)
|
|
|
|
| 12 |
# Update progress for visual feedback
|
| 13 |
progress(0, desc="Starting analysis...")
|
| 14 |
|
| 15 |
+
# Validate inputs
|
| 16 |
+
if not audio_file1 or not audio_file2:
|
| 17 |
+
return "", "", "", "", "Please upload both audio files"
|
| 18 |
+
|
| 19 |
start_time = time.time() # Record start time
|
| 20 |
|
| 21 |
# Get current process information
|
|
|
|
| 29 |
progress(0.4, desc="Processing second audio file...")
|
| 30 |
wav2 = preprocess_wav(audio_file2)
|
| 31 |
except Exception as e:
|
| 32 |
+
return "", "", "", "", f"Error processing audio files: {str(e)}"
|
| 33 |
|
| 34 |
# Extract speaker embeddings
|
| 35 |
progress(0.6, desc="Extracting voice embeddings...")
|
|
|
|
| 51 |
|
| 52 |
progress(1.0, desc="Analysis complete!")
|
| 53 |
|
| 54 |
+
# Format the HTML output for the results display
|
| 55 |
+
html_output = f"""
|
| 56 |
+
<div style="background-color: #f8f9fa; padding: 20px; border-radius: 10px; margin-top: 20px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
|
| 57 |
+
<h2 style="color: #495057; margin-bottom: 15px;">Analysis Results</h2>
|
| 58 |
+
<div style="display: flex; justify-content: space-between; margin-bottom: 20px;">
|
| 59 |
+
<div style="flex: 1; padding-right: 10px;">
|
| 60 |
+
<h4 style="color: #6c757d; margin-bottom: 5px;">Similarity Score</h4>
|
| 61 |
+
<p style="font-size: 18px; font-weight: bold; color: #212529;">{similarity:.4f}</p>
|
| 62 |
+
</div>
|
| 63 |
+
<div style="flex: 1; padding-left: 10px;">
|
| 64 |
+
<h4 style="color: #6c757d; margin-bottom: 5px;">Conclusion</h4>
|
| 65 |
+
<p style="font-size: 18px; font-weight: bold; color: {'#28a745' if similarity >= 0.80 else '#dc3545'};">{result}</p>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
<h3 style="color: #495057; margin-bottom: 15px;">Performance Metrics</h3>
|
| 69 |
+
<div style="display: flex; justify-content: space-between;">
|
| 70 |
+
<div style="flex: 1; padding-right: 10px;">
|
| 71 |
+
<h4 style="color: #6c757d; margin-bottom: 5px;">Memory Usage</h4>
|
| 72 |
+
<p style="font-size: 16px; color: #212529;">{memory_usage:.2f} MB</p>
|
| 73 |
+
</div>
|
| 74 |
+
<div style="flex: 1; padding-left: 10px;">
|
| 75 |
+
<h4 style="color: #6c757d; margin-bottom: 5px;">Execution Time</h4>
|
| 76 |
+
<p style="font-size: 16px; color: #212529;">{execution_time:.4f} seconds</p>
|
| 77 |
+
</div>
|
| 78 |
+
</div>
|
| 79 |
+
</div>
|
| 80 |
+
"""
|
| 81 |
+
|
| 82 |
+
# Return the individual values and the HTML display
|
| 83 |
return (
|
| 84 |
f"{similarity:.4f}",
|
| 85 |
+
result,
|
| 86 |
+
f"{memory_usage:.2f} MB",
|
| 87 |
f"{execution_time:.4f} seconds",
|
|
|
|
| 88 |
"" # No error
|
| 89 |
)
|
| 90 |
|
|
|
|
| 102 |
analyze_button = gr.Button("Analyze Voice Similarity", variant="primary")
|
| 103 |
|
| 104 |
# Error message display
|
| 105 |
+
error_message = gr.Markdown(visible=True)
|
| 106 |
|
| 107 |
+
# Results display section
|
| 108 |
+
with gr.Group(visible=True):
|
| 109 |
+
gr.Markdown("## Results will appear here after analysis")
|
|
|
|
| 110 |
with gr.Row():
|
| 111 |
with gr.Column():
|
| 112 |
+
similarity_display = gr.Textbox(label="Similarity Score", value="")
|
| 113 |
with gr.Column():
|
| 114 |
+
conclusion_display = gr.Textbox(label="Conclusion", value="")
|
|
|
|
|
|
|
| 115 |
with gr.Row():
|
| 116 |
with gr.Column():
|
| 117 |
+
memory_display = gr.Textbox(label="Memory Usage", value="")
|
| 118 |
with gr.Column():
|
| 119 |
+
time_display = gr.Textbox(label="Execution Time", value="")
|
| 120 |
|
| 121 |
# Handler for the analyze button
|
| 122 |
analyze_button.click(
|
|
|
|
| 127 |
conclusion_display,
|
| 128 |
memory_display,
|
| 129 |
time_display,
|
|
|
|
| 130 |
error_message
|
| 131 |
]
|
| 132 |
)
|