Hemg commited on
Commit
4751370
·
verified ·
1 Parent(s): c499895

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+
5
+ MODEL_NAME = "deeepfake-audio-B"
6
+ HF_USER = "hemg"
7
+
8
+ def prediction_function(input_file):
9
+ repo_id = HF_USER + "/" + MODEL_NAME
10
+ model = pipeline("audio-classification", model=repo_id)
11
+
12
+ try:
13
+ result = model(input_file)
14
+ predictions = {}
15
+ labels = []
16
+ for each_label in result:
17
+ predictions[each_label["label"]] = each_label["score"]
18
+ labels.append(each_label["label"])
19
+ result = predictions
20
+ except:
21
+ result = "no data provided!!"
22
+
23
+ return result
24
+
25
+
26
+ def create_interface():
27
+ interface = gr.Interface(
28
+ fn=prediction_function,
29
+ #inputs=gr.Audio(sources="upload", type="filepath"),
30
+ #inputs=gr.Audio(sources="microphone", type="filepath"),
31
+ inputs=gr.Audio(sources=["upload", "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()