Mudrock10 commited on
Commit
2856e75
·
verified ·
1 Parent(s): 7de37f6

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +111 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import time
3
+ from utils import calculate_similarity_mock
4
+
5
+ # Define the main processing function
6
+ def compare_audio(target_audio, url_1, url_2):
7
+ """
8
+ Takes a target audio file path and two URLs.
9
+ Returns a dictionary of similarity scores.
10
+ """
11
+ if target_audio is None:
12
+ raise gr.Error("Please upload a target audio file first.")
13
+
14
+ if not url_1 or not url_2:
15
+ raise gr.Warning("Please provide both source URLs for comparison.")
16
+
17
+ # In a real app, you would download the audio from the URLs here
18
+ # and run them through a model like CLAP or Wav2Vec.
19
+ # We are using a simulated backend for this demo.
20
+
21
+ results = calculate_similarity_mock(target_audio, url_1, url_2)
22
+
23
+ # Return the results for the Label component
24
+ return results
25
+
26
+ # Create the Gradio 6 Application
27
+ # 🚨 NOTE: gr.Blocks() takes NO arguments in Gradio 6.
28
+ # Theme and title go in demo.launch()
29
+ with gr.Blocks() as demo:
30
+
31
+ # Header Section
32
+ with gr.Row():
33
+ with gr.Column():
34
+ gr.Markdown("# 🎵 Audio Similarity Matcher")
35
+ gr.Markdown(
36
+ "Upload a target sound and compare it against two source audio URLs to find the best match. "
37
+ "[Built with anycoder](https://huggingface.co/spaces/akhaliq/anycoder)"
38
+ )
39
+
40
+ # Main Content
41
+ with gr.Row():
42
+ # Left Column: Inputs
43
+ with gr.Column(scale=1):
44
+ gr.Markdown("### 1. Target Audio")
45
+ target_input = gr.Audio(
46
+ sources=["upload", "microphone"],
47
+ type="filepath",
48
+ label="Upload Target Sound",
49
+ render=True
50
+ )
51
+
52
+ gr.Markdown("### 2. Compare Against Source URLs")
53
+ url_input_1 = gr.Textbox(
54
+ label="Source Audio URL #1",
55
+ placeholder="https://example.com/audio1.mp3",
56
+ lines=1
57
+ )
58
+ url_input_2 = gr.Textbox(
59
+ label="Source Audio URL #2",
60
+ placeholder="https://example.com/audio2.mp3",
61
+ lines=1
62
+ )
63
+
64
+ submit_btn = gr.Button("Analyze Similarity 🚀", variant="primary", size="lg")
65
+
66
+ # Right Column: Outputs
67
+ with gr.Column(scale=1):
68
+ gr.Markdown("### Results")
69
+ # Label component is great for classification/similarity scores
70
+ similarity_output = gr.Label(
71
+ label="Similarity Score",
72
+ num_top_classes=2
73
+ )
74
+
75
+ # JSON output for detailed debugging data
76
+ json_output = gr.JSON(
77
+ label="Detailed Analysis Data",
78
+ visible=False
79
+ )
80
+
81
+ # Event Listeners
82
+ # 🚨 Gradio 6 uses 'api_visibility' instead of just api_name
83
+ submit_btn.click(
84
+ fn=compare_audio,
85
+ inputs=[target_input, url_input_1, url_input_2],
86
+ outputs=[similarity_output],
87
+ api_visibility="public"
88
+ )
89
+
90
+ # Add example data to help users test quickly
91
+ gr.Examples(
92
+ examples=[
93
+ [None, "https://www2.cs.uic.edu/~i101/SoundFiles/BabyElephantWalk60.wav", "https://www2.cs.uic.edu/~i101/SoundFiles/CantinaBand3.wav"]
94
+ ],
95
+ inputs=[target_input, url_input_1, url_input_2]
96
+ )
97
+
98
+ # Launch the application
99
+ # 🚨 CRITICAL: Theme, CSS, and app configs go here in Gradio 6
100
+ if __name__ == "__main__":
101
+ demo.launch(
102
+ theme=gr.themes.Soft(
103
+ primary_hue="indigo",
104
+ secondary_hue="blue",
105
+ neutral_hue="slate",
106
+ radius_size="lg"
107
+ ),
108
+ footer_links=[
109
+ {"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"}
110
+ ]
111
+ )
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio>=6.0
2
+ requests
3
+ Pillow