Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 30 |
ranking = np.argsort(scores)[::-1]
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
return
|
| 34 |
|
| 35 |
# Gradio Interface
|
| 36 |
interface = gr.Interface(
|
| 37 |
fn=predict_sentiment,
|
| 38 |
inputs=gr.Textbox(lines=3, placeholder="Enter text..."),
|
| 39 |
-
outputs=gr.
|
| 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 |
)
|