bert / app.py
MennatullahHany's picture
Update app.py
76cd80f verified
Raw
History Blame Contribute Delete
978 Bytes
import gradio as gr
from transformers import pipeline
# Whisper ู„ุชุญูˆูŠู„ ุงู„ุตูˆุช ุฅู„ู‰ ู†ุต
whisper = pipeline(
"automatic-speech-recognition",
model="openai/whisper-base"
)
# ู…ูˆุฏูŠู„ูƒ
classifier = pipeline(
"text-classification",
model="MennatullahHany/Abert"
)
label_map = {
"LABEL_0": "Safe",
"LABEL_1": "Danger"
}
def predict(audio):
# ุชุญูˆูŠู„ ุงู„ุตูˆุช ุฅู„ู‰ ู†ุต
transcription = whisper(audio)["text"]
# ุชุดุบูŠู„ ุงู„ู…ูˆุฏูŠู„
result = classifier(transcription)[0]
label = label_map[result["label"]]
return {
"text":transcription,
"result": label,
"confidence": round(float(result["score"]), 4)
}
demo = gr.Interface(
fn=predict,
inputs=gr.Audio(type="filepath", label="Upload Audio"),
outputs=gr.JSON(label="Prediction"),
title="Voice Emotion Detection",
description="Upload an audio file to detect whether it is Safe or Danger."
)
demo.launch()