Spaces:
Runtime error
Runtime error
Add Gradio Audio Inference w/ clean messages
Browse files
app.py
CHANGED
|
@@ -26,6 +26,7 @@ def convert_to_wav(input_path: str) -> str:
|
|
| 26 |
|
| 27 |
def classify_audio(audio_path):
|
| 28 |
messages = []
|
|
|
|
| 29 |
ext = Path(audio_path).suffix.lower()
|
| 30 |
if ext != ".wav":
|
| 31 |
messages.append(f"🔁 Converting `{ext}` file to WAV format...")
|
|
@@ -35,7 +36,7 @@ def classify_audio(audio_path):
|
|
| 35 |
except Exception as e:
|
| 36 |
return f"❌ Failed to convert file to WAV.\n\n**Error:** {str(e)}"
|
| 37 |
|
| 38 |
-
messages.append("🔎 Running inference using YAMNet +
|
| 39 |
try:
|
| 40 |
result = classifier.classify_file(audio_path)
|
| 41 |
except Exception as e:
|
|
@@ -48,17 +49,25 @@ def classify_audio(audio_path):
|
|
| 48 |
return "\n\n".join(messages)
|
| 49 |
|
| 50 |
def upload_message(file):
|
| 51 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
# UI
|
| 54 |
with gr.Blocks() as demo:
|
| 55 |
-
gr.Markdown("🐝
|
|
|
|
| 56 |
with gr.Row():
|
| 57 |
-
audio_input = gr.Audio(type="filepath", label="Upload audio")
|
| 58 |
output_box = gr.Markdown()
|
| 59 |
|
| 60 |
audio_input.upload(fn=upload_message, inputs=audio_input, outputs=output_box)
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
| 62 |
submit_btn.click(fn=classify_audio, inputs=audio_input, outputs=output_box)
|
| 63 |
|
| 64 |
demo.launch()
|
|
|
|
| 26 |
|
| 27 |
def classify_audio(audio_path):
|
| 28 |
messages = []
|
| 29 |
+
|
| 30 |
ext = Path(audio_path).suffix.lower()
|
| 31 |
if ext != ".wav":
|
| 32 |
messages.append(f"🔁 Converting `{ext}` file to WAV format...")
|
|
|
|
| 36 |
except Exception as e:
|
| 37 |
return f"❌ Failed to convert file to WAV.\n\n**Error:** {str(e)}"
|
| 38 |
|
| 39 |
+
messages.append("🔎 Running inference using YAMNet + fine-tuned model...")
|
| 40 |
try:
|
| 41 |
result = classifier.classify_file(audio_path)
|
| 42 |
except Exception as e:
|
|
|
|
| 49 |
return "\n\n".join(messages)
|
| 50 |
|
| 51 |
def upload_message(file):
|
| 52 |
+
return (
|
| 53 |
+
"📥 **Audio uploaded successfully!**\n\n"
|
| 54 |
+
"▶️ You can now listen to the uploaded audio.\n"
|
| 55 |
+
"🧠 Click **Submit** and Inference will run shortly."
|
| 56 |
+
)
|
| 57 |
|
| 58 |
+
# Gradio UI
|
| 59 |
with gr.Blocks() as demo:
|
| 60 |
+
gr.Markdown("## 🐝 AI-Belha Classifier\nClassify Queen Bee Status in beehives using YAMNet + Fine-Tuned Model.")
|
| 61 |
+
|
| 62 |
with gr.Row():
|
| 63 |
+
audio_input = gr.Audio(type="filepath", label="Upload audio file")
|
| 64 |
output_box = gr.Markdown()
|
| 65 |
|
| 66 |
audio_input.upload(fn=upload_message, inputs=audio_input, outputs=output_box)
|
| 67 |
+
|
| 68 |
+
with gr.Row():
|
| 69 |
+
submit_btn = gr.Button("🚀 Submit for Inference")
|
| 70 |
+
|
| 71 |
submit_btn.click(fn=classify_audio, inputs=audio_input, outputs=output_box)
|
| 72 |
|
| 73 |
demo.launch()
|