Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,22 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
-
|
| 4 |
-
from transformers import AutoTokenizer, AutoModel
|
| 5 |
-
|
| 6 |
-
tokenizer = AutoTokenizer.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")
|
| 7 |
-
model = AutoModel.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")
|
| 8 |
|
| 9 |
-
# Load
|
| 10 |
sentiment_pipeline = pipeline("sentiment-analysis")
|
| 11 |
|
|
|
|
| 12 |
def analyze_sentiment(text):
|
| 13 |
-
|
| 14 |
-
return
|
| 15 |
|
| 16 |
-
#
|
| 17 |
iface = gr.Interface(
|
| 18 |
fn=analyze_sentiment,
|
| 19 |
-
inputs=gr.Textbox(lines=2, placeholder="Enter
|
| 20 |
-
outputs=
|
| 21 |
-
title="Sentiment Analysis
|
| 22 |
-
description="Enter a sentence, and the model will
|
| 23 |
)
|
| 24 |
|
| 25 |
-
# Launch the
|
| 26 |
-
iface.launch()
|
|
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# Load pre-trained sentiment analysis pipeline
|
| 5 |
sentiment_pipeline = pipeline("sentiment-analysis")
|
| 6 |
|
| 7 |
+
# Function to analyze sentiment
|
| 8 |
def analyze_sentiment(text):
|
| 9 |
+
results = sentiment_pipeline(text)
|
| 10 |
+
return {result['label']: round(result['score'], 2) for result in results}
|
| 11 |
|
| 12 |
+
# Gradio Interface
|
| 13 |
iface = gr.Interface(
|
| 14 |
fn=analyze_sentiment,
|
| 15 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter a sentence here..."),
|
| 16 |
+
outputs=gr.Label(num_top_classes=3),
|
| 17 |
+
title="Sentiment Analysis",
|
| 18 |
+
description="Enter a sentence, and the model will classify it as Positive, Negative, or Neutral."
|
| 19 |
)
|
| 20 |
|
| 21 |
+
# Launch the app
|
| 22 |
+
iface.launch()
|