Spaces:
Runtime error
Runtime error
File size: 1,965 Bytes
7913995 9c86d9a 7913995 9c86d9a 7913995 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import tensorflow as tf
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
import opendatasets as od
import gradio as gr
import pandas as pd
import plotly.express as plt
tf.get_logger().setLevel("ERROR")
# create tokenizer from pre-trained model
tokenizer = AutoTokenizer.from_pretrained(
"blanchefort/rubert-base-cased-sentiment-rurewiews"
)
# Load the model
model = AutoModelForSequenceClassification.from_pretrained(
"blanchefort/rubert-base-cased-sentiment-rurewiews"
)
# Create a pipeline for the model
pipe = pipeline(
"text-classification", model="blanchefort/rubert-base-cased-sentiment-rurewiews"
)
# load review from open dataset
od.download_kaggle_dataset("vigneshwarsofficial/reviews", data_dir="restaurent_review")
prediction_data = pd.read_csv(
"restaurent_review/reviews/Restaurant_Reviews.tsv", delimiter="\t"
)
# popping irrelevant coloumn
prediction_data.pop("Liked")
# making a list
data = list(prediction_data["Review"])
# making prediction using pipe
results = pipe(data)
# Categorizing result
positive_counter = 0
negative_counter = 0
neutral_counter = 0
for x in results:
if x["label"] == "POSITIVE":
positive_counter = positive_counter + 1
elif x["label"] == "NEGATIVE":
negative_counter = negative_counter + 1
else:
neutral_counter = neutral_counter + 1
result_data = pd.DataFrame(
{
"count": [positive_counter, negative_counter, neutral_counter],
"sentiment": ["Positive", "Negative", "Neutral"],
}
)
# create bar chart interface on gradio
def plotly_plot():
p = plt.bar(
result_data,
x="sentiment",
y="count",
title="Restaurent Review Analysis",
color="count",
)
return p
# show the results
outputs = gr.Plot()
demo = gr.Interface(
fn=plotly_plot,
inputs=None,
outputs=outputs,
title="Restaurant Customer Review Sentiment Analysis",
)
demo.launch()
|