MennatullahHany commited on
Commit
106407e
ยท
verified ยท
1 Parent(s): f777f78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -16
app.py CHANGED
@@ -13,32 +13,32 @@ classifier = pipeline(
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
- return {
28
- "transcription": transcription,
29
- "model_output": result
30
- }
31
 
32
- except Exception as e:
33
- return {
34
- "error": str(e)
35
- }
36
 
37
  demo = gr.Interface(
38
  fn=predict,
39
  inputs=gr.Audio(type="filepath", label="Upload Audio"),
40
  outputs=gr.JSON(label="Prediction"),
41
- title="Voice Emotion Detection"
 
42
  )
43
 
44
  demo.launch()
 
13
  model="MennatullahHany/Abert"
14
  )
15
 
16
+ label_map = {
17
+ "LABEL_0": "Safe",
18
+ "LABEL_1": "Danger"
19
+ }
20
+
21
  def predict(audio):
 
 
 
22
 
23
+ # ุชุญูˆูŠู„ ุงู„ุตูˆุช ุฅู„ู‰ ู†ุต
24
+ transcription = whisper(audio)["text"]
25
 
26
+ # ุชุดุบูŠู„ ุงู„ู…ูˆุฏูŠู„
27
+ result = classifier(transcription)[0]
28
 
29
+ label = label_map[result["label"]]
 
 
 
30
 
31
+ return {
32
+ "emotion": label,
33
+ "confidence": round(float(result["score"]), 4)
34
+ }
35
 
36
  demo = gr.Interface(
37
  fn=predict,
38
  inputs=gr.Audio(type="filepath", label="Upload Audio"),
39
  outputs=gr.JSON(label="Prediction"),
40
+ title="Voice Emotion Detection",
41
+ description="Upload an audio file to detect whether it is Safe or Danger."
42
  )
43
 
44
  demo.launch()