MennatullahHany commited on
Commit
5eb7fd9
ยท
verified ยท
1 Parent(s): 41d8e57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -33
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
- transcription = whisper(audio)["text"]
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
- probabilities[label] = round(float(item["score"]), 4)
 
40
 
41
- if item["score"] > best_score:
42
- best_score = item["score"]
43
- best_label = label
 
 
44
 
45
- return {
46
- "text": transcription,
47
- "emotion": best_label,
48
- "confidence": round(best_score, 4),
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()