ktr008 commited on
Commit
28180d3
·
verified ·
1 Parent(s): 1c1509c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -26,17 +26,19 @@ def predict_sentiment(text):
26
  scores = output[0][0].detach().numpy()
27
  scores = softmax(scores)
28
 
29
- # Get sentiment labels and scores (floating-point values)
30
  ranking = np.argsort(scores)[::-1]
31
- result = {config.id2label[ranking[i]]: float(scores[ranking[i]]) for i in range(scores.shape[0])}
 
 
32
 
33
- return result
34
 
35
  # Gradio Interface
36
  interface = gr.Interface(
37
  fn=predict_sentiment,
38
  inputs=gr.Textbox(lines=3, placeholder="Enter text..."),
39
- outputs=gr.Label(num_top_classes=3), # Display without JSON
40
  title="Fine-Tuned Sentiment Analysis",
41
  description="Enter a sentence to analyze its sentiment (Positive, Neutral, Negative).",
42
  )
 
26
  scores = output[0][0].detach().numpy()
27
  scores = softmax(scores)
28
 
29
+ # Get sentiment labels and scores
30
  ranking = np.argsort(scores)[::-1]
31
+ output_text = "\n".join(
32
+ [f"{config.id2label[ranking[i]]}: {float(scores[ranking[i]])}" for i in range(scores.shape[0])]
33
+ )
34
 
35
+ return output_text
36
 
37
  # Gradio Interface
38
  interface = gr.Interface(
39
  fn=predict_sentiment,
40
  inputs=gr.Textbox(lines=3, placeholder="Enter text..."),
41
+ outputs=gr.Textbox(), # Display output as plain text
42
  title="Fine-Tuned Sentiment Analysis",
43
  description="Enter a sentence to analyze its sentiment (Positive, Neutral, Negative).",
44
  )