Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,51 +10,36 @@ whisper = pipeline(
|
|
| 10 |
# ู
ูุฏููู
|
| 11 |
classifier = pipeline(
|
| 12 |
"text-classification",
|
| 13 |
-
model="MennatullahHany/Abert"
|
| 14 |
-
return_all_scores=True
|
| 15 |
)
|
| 16 |
|
| 17 |
-
label_map = {
|
| 18 |
-
"LABEL_0": "Safe",
|
| 19 |
-
"LABEL_1": "Danger"
|
| 20 |
-
}
|
| 21 |
-
|
| 22 |
def predict(audio):
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
# ุชุตููู ุงููุต
|
| 28 |
-
scores = classifier(transcription)[0]
|
| 29 |
-
|
| 30 |
-
probabilities = {}
|
| 31 |
-
|
| 32 |
-
best_label = ""
|
| 33 |
-
best_score = 0
|
| 34 |
-
|
| 35 |
-
for item in scores:
|
| 36 |
-
|
| 37 |
-
label = label_map.get(item["label"], item["label"])
|
| 38 |
|
| 39 |
-
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
"probabilities": probabilities
|
| 50 |
-
}
|
| 51 |
|
| 52 |
demo = gr.Interface(
|
| 53 |
fn=predict,
|
| 54 |
inputs=gr.Audio(type="filepath", label="Upload Audio"),
|
| 55 |
outputs=gr.JSON(label="Prediction"),
|
| 56 |
-
title="Voice Emotion Detection"
|
| 57 |
-
description="Upload an audio file to detect whether it is Safe or Danger."
|
| 58 |
)
|
| 59 |
|
| 60 |
demo.launch()
|
|
|
|
| 10 |
# ู
ูุฏููู
|
| 11 |
classifier = pipeline(
|
| 12 |
"text-classification",
|
| 13 |
+
model="MennatullahHany/Abert"
|
|
|
|
| 14 |
)
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def predict(audio):
|
| 17 |
+
try:
|
| 18 |
+
# ุชุญููู ุงูุตูุช ุฅูู ูุต
|
| 19 |
+
transcription = whisper(audio)["text"]
|
| 20 |
|
| 21 |
+
# ุชุดุบูู ู
ูุฏููู
|
| 22 |
+
result = classifier(transcription)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
# ุงุทุจุน ุงููุชูุฌุฉ ูู ุงูู Logs
|
| 25 |
+
print(result)
|
| 26 |
|
| 27 |
+
# ุฃุฑุฌุนูุง ูู
ุง ูู
|
| 28 |
+
return {
|
| 29 |
+
"transcription": transcription,
|
| 30 |
+
"model_output": result
|
| 31 |
+
}
|
| 32 |
|
| 33 |
+
except Exception as e:
|
| 34 |
+
return {
|
| 35 |
+
"error": str(e)
|
| 36 |
+
}
|
|
|
|
|
|
|
| 37 |
|
| 38 |
demo = gr.Interface(
|
| 39 |
fn=predict,
|
| 40 |
inputs=gr.Audio(type="filepath", label="Upload Audio"),
|
| 41 |
outputs=gr.JSON(label="Prediction"),
|
| 42 |
+
title="Voice Emotion Detection"
|
|
|
|
| 43 |
)
|
| 44 |
|
| 45 |
demo.launch()
|