Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load pre-trained sentiment analysis model
|
| 5 |
+
sentiment_model = pipeline("sentiment-analysis")
|
| 6 |
+
|
| 7 |
+
# Define function to use the model
|
| 8 |
+
def analyze_sentiment(text):
|
| 9 |
+
result = sentiment_model(text)[0]
|
| 10 |
+
return f"Label: {result['label']} | Confidence: {result['score']:.2f}"
|
| 11 |
+
|
| 12 |
+
# Create Gradio interface
|
| 13 |
+
demo = gr.Interface(
|
| 14 |
+
fn=analyze_sentiment,
|
| 15 |
+
inputs=gr.Textbox(lines=3, placeholder="Type a sentence here..."),
|
| 16 |
+
outputs="text",
|
| 17 |
+
title="Simple Sentiment Analyzer",
|
| 18 |
+
description="Find out if your text is Positive or Negative using a BERT model."
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
# Launch the app
|
| 22 |
+
demo.launch()
|