Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,18 @@
|
|
1 |
-
|
2 |
-
from transformers import BertTokenizer, BertForSequenceClassification
|
3 |
-
import torch
|
4 |
-
|
5 |
-
# Load the model and tokenizer from the folder in Hugging Face space
|
6 |
-
model_folder = "FYP_Model" # Replace with your actual username and model name
|
7 |
-
tokenizer = BertTokenizer.from_pretrained(model_folder)
|
8 |
-
model = BertForSequenceClassification.from_pretrained(model_folder)
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
audio_content = audio_file.read()
|
13 |
-
inputs = tokenizer(audio_content, return_tensors="pt", truncation=True)
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
19 |
|
20 |
-
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
fn=classify_audio,
|
25 |
-
inputs=gr.Audio(type="file", label="Upload or Record Audio"),
|
26 |
-
outputs=gr.Textbox(),
|
27 |
-
live=True,
|
28 |
)
|
29 |
-
|
30 |
-
# Launch the Gradio interface
|
31 |
-
iface.launch()
|
|
|
1 |
+
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
model_id = "arham061/distilhubert-finetuned-RHD_Dataset"
|
4 |
+
pipe = pipeline("audio-classification", model=model_id)
|
|
|
|
|
5 |
|
6 |
+
def classify_audio(filepath):
|
7 |
+
preds = pipe(filepath)
|
8 |
+
outputs = {}
|
9 |
+
for p in preds:
|
10 |
+
outputs[p["label"]] = p["score"]
|
11 |
+
return outputs
|
12 |
|
13 |
+
import gradio as gr
|
14 |
|
15 |
+
demo = gr.Interface(
|
16 |
+
fn=classify_audio, inputs=gr.Audio(type="filepath"), outputs="label"
|
|
|
|
|
|
|
|
|
17 |
)
|
18 |
+
demo.launch(debug=True)
|
|
|
|