Jeffrey0216 commited on
Commit
e9b85e8
·
verified ·
1 Parent(s): 9319d43

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -1,20 +1,23 @@
1
  import gradio as gr
 
2
  from transformers import pipeline
 
3
 
4
- classifier = pipeline(
5
- "sentiment-analysis",
6
- model="distilbert-base-uncased-finetuned-sst-2-english"
7
- )
8
 
9
- def predict(text):
10
- return classifier(text)[0]["label"]
11
 
12
- with gr.Blocks() as demo:
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
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
 
 
 
 
 
 
 
 
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