Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -10,6 +10,8 @@ matplotlib.use("Agg")
|
|
| 10 |
import matplotlib.pyplot as plt
|
| 11 |
import numpy as np
|
| 12 |
|
|
|
|
|
|
|
| 13 |
DATASET_INFO = {
|
| 14 |
"total_clips": 50000,
|
| 15 |
"machines": ["fan", "pump", "compressor", "conveyor_belt", "electric_motor", "valve"],
|
|
@@ -57,6 +59,12 @@ def predict_anomaly(audio_file, machine_type):
|
|
| 57 |
if audio_file is None:
|
| 58 |
return "Please upload an audio file.", None, None
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
import random
|
| 61 |
random.seed(hash(str(audio_file)) % 1000)
|
| 62 |
is_anomaly = random.random() > 0.5
|
|
@@ -91,7 +99,7 @@ with gr.Blocks(theme=theme, title="AnomalyMachine-50K Demo") as app:
|
|
| 91 |
<div style="text-align: center; padding: 20px;">
|
| 92 |
<h1>π AnomalyMachine-50K</h1>
|
| 93 |
<p>Synthetic Industrial Machine Sound Anomaly Detection Dataset</p>
|
| 94 |
-
<p><a href="https://huggingface.co/datasets/AnomalyMachine-50K" target="_blank">View Dataset β</a></p>
|
| 95 |
</div>
|
| 96 |
""")
|
| 97 |
|
|
@@ -113,7 +121,8 @@ with gr.Blocks(theme=theme, title="AnomalyMachine-50K Demo") as app:
|
|
| 113 |
predict_btn.click(
|
| 114 |
fn=predict_anomaly,
|
| 115 |
inputs=[audio_input, machine_dropdown],
|
| 116 |
-
outputs=[result_html, input_spec, ref_spec]
|
|
|
|
| 117 |
)
|
| 118 |
|
| 119 |
with gr.Tab("π Explore Dataset"):
|
|
@@ -127,7 +136,7 @@ with gr.Blocks(theme=theme, title="AnomalyMachine-50K Demo") as app:
|
|
| 127 |
<li>Normal: {DATASET_INFO['normal_ratio']:.0%} | Anomalous: {DATASET_INFO['anomalous_ratio']:.0%}</li>
|
| 128 |
</ul>
|
| 129 |
<p style="text-align: center;">
|
| 130 |
-
<a href="https://huggingface.co/datasets/AnomalyMachine-50K" target="_blank">
|
| 131 |
<button style="padding: 10px 20px; font-size: 16px;">π₯ Download Dataset</button>
|
| 132 |
</a>
|
| 133 |
</p>
|
|
@@ -138,7 +147,7 @@ with gr.Blocks(theme=theme, title="AnomalyMachine-50K Demo") as app:
|
|
| 138 |
<div style="text-align: center; padding: 20px; border-top: 1px solid #333; margin-top: 40px;">
|
| 139 |
<p style="color: #888; font-size: 14px;">
|
| 140 |
License: CC-BY 4.0 |
|
| 141 |
-
<a href="https://huggingface.co/datasets/AnomalyMachine-50K" target="_blank">Dataset</a> |
|
| 142 |
<a href="https://github.com/mandip42/anomaly-machine-50k" target="_blank">GitHub</a>
|
| 143 |
</p>
|
| 144 |
</div>
|
|
|
|
| 10 |
import matplotlib.pyplot as plt
|
| 11 |
import numpy as np
|
| 12 |
|
| 13 |
+
DATASET_URL = "https://huggingface.co/datasets/mandipgoswami/AnomalyMachine-50K"
|
| 14 |
+
|
| 15 |
DATASET_INFO = {
|
| 16 |
"total_clips": 50000,
|
| 17 |
"machines": ["fan", "pump", "compressor", "conveyor_belt", "electric_motor", "valve"],
|
|
|
|
| 59 |
if audio_file is None:
|
| 60 |
return "Please upload an audio file.", None, None
|
| 61 |
|
| 62 |
+
# Gradio Audio can return dict with "path" key in some versions
|
| 63 |
+
if isinstance(audio_file, dict):
|
| 64 |
+
audio_file = audio_file.get("path") or audio_file.get("name")
|
| 65 |
+
if not audio_file:
|
| 66 |
+
return "Please upload an audio file.", None, None
|
| 67 |
+
|
| 68 |
import random
|
| 69 |
random.seed(hash(str(audio_file)) % 1000)
|
| 70 |
is_anomaly = random.random() > 0.5
|
|
|
|
| 99 |
<div style="text-align: center; padding: 20px;">
|
| 100 |
<h1>π AnomalyMachine-50K</h1>
|
| 101 |
<p>Synthetic Industrial Machine Sound Anomaly Detection Dataset</p>
|
| 102 |
+
<p><a href="https://huggingface.co/datasets/mandipgoswami/AnomalyMachine-50K" target="_blank">View Dataset β</a></p>
|
| 103 |
</div>
|
| 104 |
""")
|
| 105 |
|
|
|
|
| 121 |
predict_btn.click(
|
| 122 |
fn=predict_anomaly,
|
| 123 |
inputs=[audio_input, machine_dropdown],
|
| 124 |
+
outputs=[result_html, input_spec, ref_spec],
|
| 125 |
+
api_name="predict",
|
| 126 |
)
|
| 127 |
|
| 128 |
with gr.Tab("π Explore Dataset"):
|
|
|
|
| 136 |
<li>Normal: {DATASET_INFO['normal_ratio']:.0%} | Anomalous: {DATASET_INFO['anomalous_ratio']:.0%}</li>
|
| 137 |
</ul>
|
| 138 |
<p style="text-align: center;">
|
| 139 |
+
<a href="https://huggingface.co/datasets/mandipgoswami/AnomalyMachine-50K" target="_blank">
|
| 140 |
<button style="padding: 10px 20px; font-size: 16px;">π₯ Download Dataset</button>
|
| 141 |
</a>
|
| 142 |
</p>
|
|
|
|
| 147 |
<div style="text-align: center; padding: 20px; border-top: 1px solid #333; margin-top: 40px;">
|
| 148 |
<p style="color: #888; font-size: 14px;">
|
| 149 |
License: CC-BY 4.0 |
|
| 150 |
+
<a href="https://huggingface.co/datasets/mandipgoswami/AnomalyMachine-50K" target="_blank">Dataset</a> |
|
| 151 |
<a href="https://github.com/mandip42/anomaly-machine-50k" target="_blank">GitHub</a>
|
| 152 |
</p>
|
| 153 |
</div>
|