Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the sentiment-analysis pipeline
|
5 |
+
sentiment_analyzer = pipeline("sentiment-analysis")
|
6 |
+
|
7 |
+
# Define the function to analyze text sentiment
|
8 |
+
def analyze_sentiment(text):
|
9 |
+
result = sentiment_analyzer(text)
|
10 |
+
sentiment = result[0]['label']
|
11 |
+
score = result[0]['score']
|
12 |
+
return f"Sentiment: {sentiment} (Confidence: {score:.2f})"
|
13 |
+
|
14 |
+
# Create the Gradio interface
|
15 |
+
app = gr.Interface(
|
16 |
+
fn=analyze_sentiment,
|
17 |
+
inputs=gr.Textbox(label="Enter text to analyze"),
|
18 |
+
outputs=gr.Textbox(label="Sentiment Analysis Result"),
|
19 |
+
title="Text Sentiment Analyzer",
|
20 |
+
description="Analyze the sentiment of text input using a pre-trained NLP model."
|
21 |
+
)
|
22 |
+
|
23 |
+
if __name__ == "__main__":
|
24 |
+
app.launch()
|