Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,22 @@
|
|
| 1 |
-
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
-
|
| 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}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|