Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,23 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
"sentiment-analysis",
|
| 6 |
-
model="distilbert-base-uncased-finetuned-sst-2-english"
|
| 7 |
-
)
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
-
|
| 13 |
-
gr.Markdown("# Sentiment Analysis")
|
| 14 |
-
inp = gr.Textbox(label="Enter text")
|
| 15 |
-
out = gr.Textbox(label="Sentiment")
|
| 16 |
-
btn = gr.Button("Analyze")
|
| 17 |
-
btn.click(predict, inp, out)
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
from transformers import pipeline
|
| 4 |
+
from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
|
| 5 |
|
| 6 |
+
df = pd.read_csv("WhatsApp.csv")
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-uncased-finetuned-sst-2-english')
|
| 9 |
+
model = DistilBertForSequenceClassification.from_pretrained('distilbert-base-uncased-finetuned-sst-2-english')
|
| 10 |
|
| 11 |
+
nlp = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
def sentiment_analysis_model(review):
|
| 14 |
+
res = nlp(review)
|
| 15 |
+
label = res[0]['label']
|
| 16 |
+
score = res[0]['score']
|
| 17 |
+
output = f"{label}, Score: {score}"
|
| 18 |
+
return output
|
| 19 |
+
|
| 20 |
+
demo = gr.Interface(fn=sentiment_analysis_model, inputs="text", outputs="text", title="SENTIMENT ANALYSIS using DistilBert model",
|
| 21 |
+
description="Sentiment Analysis using Pretrained DistilBert model. The DistilBert model is trained on a sample data of google playstore reviews for WhatsApp application. Provide a review and the model will classify it to be POSITIVE or NEGATIVE")
|
| 22 |
+
demo.launch()
|
| 23 |
|