Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,12 @@
|
|
| 1 |
-
import
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 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()
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load a multi-class sentiment model
|
| 5 |
+
model_name = "cardiffnlp/twitter-roberta-base-sentiment"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 8 |
+
sentiment_model = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
| 9 |
|
|
|
|
| 10 |
def analyze_sentiment(text):
|
| 11 |
result = sentiment_model(text)[0]
|
| 12 |
return f"Label: {result['label']} | Confidence: {result['score']:.2f}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|