Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Load the sentiment analysis model
|
5 |
+
sentiment_analysis = pipeline("sentiment-analysis")
|
6 |
+
|
7 |
+
# Define the prediction function
|
8 |
+
def predict_sentiment(text):
|
9 |
+
result = sentiment_analysis(text)[0]
|
10 |
+
label = result['label']
|
11 |
+
confidence = round(result['score'], 4)
|
12 |
+
return f"Sentiment: {label}, Confidence: {confidence}"
|
13 |
+
|
14 |
+
# Create a Gradio interface
|
15 |
+
interface = gr.Interface(fn=predict_sentiment,
|
16 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Type your text here..."),
|
17 |
+
outputs="text",
|
18 |
+
title="Text Sentiment Analysis",
|
19 |
+
description="This tool predicts the sentiment of the entered text. Sentiment can be positive, negative, or neutral.")
|
20 |
+
|
21 |
+
# Launch the application
|
22 |
+
interface.launch()
|