haripriyaram commited on
Commit
f3daf50
·
verified ·
1 Parent(s): 5dd75c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -17
app.py CHANGED
@@ -6,24 +6,11 @@ learn = from_pretrained_fastai("haripriyaram/Text-emotion-Recognizer-Model")
6
 
7
  # Prediction function
8
  def predict_emotion(text):
9
- #pred_label, _, probs = learn.predict(text)
10
- # pred, pred_idx, probs = learn.predict(text)
11
 
12
  # # Handle nested vocab if needed
13
- # vocab = learn.dls.vocab[0] if isinstance(learn.dls.vocab[1], list) else learn.dls.vocab
14
- # probs_dict = {label: float(prob) for label, prob in zip(vocab, probs)}
15
- # Perform prediction on the input text
16
- prediction, class_index, probabilities = learn.predict(text)
17
-
18
- # Get the list of class labels
19
- class_labels = learn.dls.vocab
20
-
21
- # Create a dictionary of probabilities
22
- probs_dict = dict(zip(class_labels, probabilities.tolist()))
23
-
24
- print(f"Input text: {input_text}")
25
- print(f"Predicted emotion: {prediction}")
26
- print(f"Probabilities: {probs_dict}")
27
 
28
  return prediction, probs_dict
29
 
@@ -33,7 +20,7 @@ iface = gr.Interface(
33
  inputs=gr.Textbox(lines=2, placeholder="Enter a sentence..."),
34
  outputs=[
35
  gr.Label(label="Predicted Emotion"),
36
- gr.JSON(label="Confidence Scores")
37
  ],
38
  title="🎭 Emotion Classifier (ML Service)",
39
  description="Enter a sentence and the model will predict the corresponding emotion.",
 
6
 
7
  # Prediction function
8
  def predict_emotion(text):
9
+ pred_label, _, probs = learn.predict(text)
 
10
 
11
  # # Handle nested vocab if needed
12
+ vocab = learn.dls.vocab[0] if isinstance(learn.dls.vocab[1], list) else learn.dls.vocab
13
+ probs_dict = {label: float(prob) for label, prob in zip(vocab, probs)}
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  return prediction, probs_dict
16
 
 
20
  inputs=gr.Textbox(lines=2, placeholder="Enter a sentence..."),
21
  outputs=[
22
  gr.Label(label="Predicted Emotion"),
23
+ #gr.JSON(label="Confidence Scores")
24
  ],
25
  title="🎭 Emotion Classifier (ML Service)",
26
  description="Enter a sentence and the model will predict the corresponding emotion.",