Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
|
5 |
+
MODEL_NAME = "catsound"
|
6 |
+
HF_USER = "universalml"
|
7 |
+
|
8 |
+
|
9 |
+
def prediction_function(input_file):
|
10 |
+
repo_id = HF_USER + "/" + MODEL_NAME
|
11 |
+
model = pipeline("audio-classification", model=repo_id)
|
12 |
+
|
13 |
+
try:
|
14 |
+
result = model(input_file)
|
15 |
+
predictions = {}
|
16 |
+
labels = []
|
17 |
+
for each_label in result:
|
18 |
+
predictions[each_label["label"]] = each_label["score"]
|
19 |
+
labels.append(each_label["label"])
|
20 |
+
result = predictions
|
21 |
+
except:
|
22 |
+
result = "no data provided!!"
|
23 |
+
|
24 |
+
return result
|
25 |
+
|
26 |
+
|
27 |
+
def create_interface():
|
28 |
+
interface = gr.Interface(
|
29 |
+
fn=prediction_function,
|
30 |
+
# inputs=gr.Audio(sources="upload", type="filepath"),
|
31 |
+
inputs=gr.Audio(sources="microphone", type="filepath"),
|
32 |
+
outputs=gr.Label(num_top_classes=3),
|
33 |
+
title=MODEL_NAME,
|
34 |
+
)
|
35 |
+
|
36 |
+
interface.launch()
|
37 |
+
|
38 |
+
|
39 |
+
create_interface()
|