Spaces:
Sleeping
Sleeping
chayanbhansali
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load pre-trained sentiment analysis model from Hugging Face
|
5 |
+
classifier = pipeline("sentiment-analysis")
|
6 |
+
|
7 |
+
# Define the function to predict sentiment
|
8 |
+
def predict_sentiment(text):
|
9 |
+
result = classifier(text)
|
10 |
+
label = result[0]['label']
|
11 |
+
confidence = result[0]['score']
|
12 |
+
return f"Sentiment: {label}, Confidence: {confidence:.2f}"
|
13 |
+
|
14 |
+
# Gradio interface
|
15 |
+
interface = gr.Interface(fn=predict_sentiment, inputs="text", outputs="text",
|
16 |
+
title="Sentiment Analysis", description="Enter text to predict sentiment")
|
17 |
+
|
18 |
+
interface.launch()
|