universalml commited on
Commit
bf00da2
·
verified ·
1 Parent(s): b080d2a

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+
5
+ modelName = "asdww"
6
+ hfUser = "universalml"
7
+
8
+
9
+ def prediction_function(inputFile):
10
+ # get user name of their hugging face
11
+ modelPath = hfUser + "/" + modelName
12
+ # takes some time
13
+ classifier = pipeline("audio-classification", model=modelPath)
14
+
15
+ try:
16
+ result = classifier(inputFile)
17
+ predictions = dict()
18
+ labels = []
19
+ for eachLabel in result:
20
+ predictions[eachLabel["label"]] = eachLabel["score"]
21
+ labels.append(eachLabel["label"])
22
+ result = predictions
23
+ except:
24
+ result = "no data provided!!"
25
+
26
+ return result
27
+
28
+
29
+ # change modelName parameter
30
+ def create_demo():
31
+ demo = gr.Interface(
32
+ fn=prediction_function,
33
+ # inputs=gr.Audio(sources="upload", type="filepath"),
34
+ inputs=gr.Audio(sources="microphone", type="filepath"),
35
+ outputs=gr.Label(num_top_classes=3),
36
+ )
37
+ demo.launch()
38
+
39
+
40
+ create_demo()