Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Load the sentiment analysis pipeline
|
5 |
+
classifier = pipeline("sentiment-analysis")
|
6 |
+
|
7 |
+
# Define the prediction function
|
8 |
+
def analyze_sentiment(text):
|
9 |
+
result = classifier(text)[0]
|
10 |
+
label = result['label']
|
11 |
+
score = round(result['score'], 3)
|
12 |
+
return f"Sentiment: {label} (Confidence: {score})"
|
13 |
+
|
14 |
+
# Create the Gradio interface
|
15 |
+
interface = gr.Interface(
|
16 |
+
fn=analyze_sentiment,
|
17 |
+
inputs=gr.Textbox(lines=4, placeholder="Enter some text here..."),
|
18 |
+
outputs="text",
|
19 |
+
title="Sentiment Analysis with Hugging Face 🤗",
|
20 |
+
description="Enter text to find out if the sentiment is positive, negative, or neutral."
|
21 |
+
)
|
22 |
+
|
23 |
+
# Run the app
|
24 |
+
if __name__ == "__main__":
|
25 |
+
interface.launch()
|