Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
|
|
|
|
| 3 |
sentiment_pipeline = pipeline(
|
| 4 |
"text-classification",
|
| 5 |
model="hasanmustafa0503/SentimentModel",
|
| 6 |
tokenizer="hasanmustafa0503/SentimentModel"
|
| 7 |
)
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Initialize the sentiment analysis pipeline
|
| 5 |
sentiment_pipeline = pipeline(
|
| 6 |
"text-classification",
|
| 7 |
model="hasanmustafa0503/SentimentModel",
|
| 8 |
tokenizer="hasanmustafa0503/SentimentModel"
|
| 9 |
)
|
| 10 |
|
| 11 |
+
# Function to classify sentiment of text
|
| 12 |
+
def classify_sentiment(text):
|
| 13 |
+
result = sentiment_pipeline(text)
|
| 14 |
+
return result[0]['label'], result[0]['score']
|
| 15 |
+
|
| 16 |
+
# Define Gradio interface
|
| 17 |
+
iface = gr.Interface(
|
| 18 |
+
fn=classify_sentiment, # Function to call
|
| 19 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."), # Text input box
|
| 20 |
+
outputs=[gr.Label(), gr.Number()], # Label for sentiment and score
|
| 21 |
+
title="Sentiment Analysis", # Title for the app
|
| 22 |
+
description="Enter some text, and this tool will predict the sentiment as POSITIVE or NEGATIVE along with the confidence score.", # Description
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# Launch the app
|
| 26 |
+
iface.launch()
|
| 27 |
+
|
| 28 |
|