sami606713 commited on
Commit
bc8c795
·
verified ·
1 Parent(s): adf299f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -31
app.py CHANGED
@@ -30,36 +30,36 @@ if uploaded_file is not None:
30
  st.audio(uploaded_file)
31
 
32
  # Perform emotion classification
33
- st.write("Classifying...")
34
- try:
35
- inputs = feature_extractor(audio_input, sampling_rate=sample_rate, return_tensors="pt")
36
-
37
- # Make prediction
38
- with torch.no_grad():
39
- outputs = model(**inputs)
40
-
41
- embeddings = outputs.pooler_output
42
-
43
- # Apply a classification head on top of the embeddings
44
- id2label={
45
- 0:"angry",
46
- 1:'calm',
47
- 2:'disgust',
48
- 3:'fearful',
49
- 4:'happy',
50
- 5:'neutral',
51
- 6:'sad',
52
- 7:'surprised'
53
- }
54
- classifier = torch.nn.Linear(embeddings.shape[-1], len(id2label))
55
-
56
- # Pass embeddings through the classifier
57
- logits = classifier(embeddings)
58
-
59
- # Get predicted class
60
- predicted_class_idx = logits.argmax(-1).item()
61
- predicted_class = id2label[predicted_class_idx]
62
-
63
- st.write(f"Predicted Emotion: {predicted_class}")
64
  except Exception as e:
65
  st.write(f"Error during classification: {e}")
 
30
  st.audio(uploaded_file)
31
 
32
  # Perform emotion classification
33
+ if st.button("Classifying"):
34
+ try:
35
+ inputs = feature_extractor(audio_input, sampling_rate=sample_rate, return_tensors="pt")
36
+
37
+ # Make prediction
38
+ with torch.no_grad():
39
+ outputs = model(**inputs)
40
+
41
+ embeddings = outputs.pooler_output
42
+
43
+ # Apply a classification head on top of the embeddings
44
+ id2label={
45
+ 0:"angry",
46
+ 1:'calm',
47
+ 2:'disgust',
48
+ 3:'fearful',
49
+ 4:'happy',
50
+ 5:'neutral',
51
+ 6:'sad',
52
+ 7:'surprised'
53
+ }
54
+ classifier = torch.nn.Linear(embeddings.shape[-1], len(id2label))
55
+
56
+ # Pass embeddings through the classifier
57
+ logits = classifier(embeddings)
58
+
59
+ # Get predicted class
60
+ predicted_class_idx = logits.argmax(-1).item()
61
+ predicted_class = id2label[predicted_class_idx]
62
+
63
+ st.write(f"Predicted Emotion: {predicted_class}")
64
  except Exception as e:
65
  st.write(f"Error during classification: {e}")