Spaces:
Runtime error
Runtime error
Upload 4 files
Browse files- README.md +4 -5
- app.py +66 -0
- requirements.txt +17 -0
README.md
CHANGED
|
@@ -1,13 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title: Reviews
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 3.16.2
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
-
license: openrail
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Reviews Sentiment Analysis App
|
| 3 |
+
emoji: 🏃
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 3.16.2
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Import the required Libraries
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import numpy as np
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import pickle
|
| 6 |
+
import transformers
|
| 7 |
+
from transformers import AutoTokenizer, AutoConfig,AutoModelForSequenceClassification,TFAutoModelForSequenceClassification
|
| 8 |
+
from scipy.special import softmax
|
| 9 |
+
# Requirements
|
| 10 |
+
model_path = "Kaludi/Reviews-Sentiment-Analysis"
|
| 11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 12 |
+
config = AutoConfig.from_pretrained(model_path)
|
| 13 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
| 14 |
+
|
| 15 |
+
# Preprocess text (username and link placeholders)
|
| 16 |
+
def preprocess(text):
|
| 17 |
+
new_text = []
|
| 18 |
+
for t in text.split(" "):
|
| 19 |
+
t = "@user" if t.startswith("@") and len(t) > 1 else t
|
| 20 |
+
t = "http" if t.startswith("http") else t
|
| 21 |
+
new_text.append(t)
|
| 22 |
+
return " ".join(new_text)
|
| 23 |
+
|
| 24 |
+
# ---- Function to process the input and return prediction
|
| 25 |
+
def sentiment_analysis(text):
|
| 26 |
+
text = preprocess(text)
|
| 27 |
+
|
| 28 |
+
encoded_input = tokenizer(text, return_tensors = "pt") # for PyTorch-based models
|
| 29 |
+
output = model(**encoded_input)
|
| 30 |
+
scores_ = output[0][0].detach().numpy()
|
| 31 |
+
scores_ = softmax(scores_)
|
| 32 |
+
|
| 33 |
+
# Format output dict of scores
|
| 34 |
+
labels = ["Negative", "Positive"]
|
| 35 |
+
scores = {l:float(s) for (l,s) in zip(labels, scores_) }
|
| 36 |
+
|
| 37 |
+
return scores
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
# ---- Gradio app interface
|
| 41 |
+
app = gr.Interface(fn = sentiment_analysis,
|
| 42 |
+
inputs = gr.Textbox("Write your text or review here..."),
|
| 43 |
+
outputs = "label",
|
| 44 |
+
title = "Sentiment Analysis of Customer Reviews",
|
| 45 |
+
description = "A tool that analyzes the overall sentiment of customer reviews for a specific product or servicem, wheather it's positive or negative. This analysis is performed by using natural language processing algorithms and machine learning from the model 'Reviews-Sentiment-Analysis' trained by Kaludi, allowing businesses to gain valuable insights into customer satisfaction and improve their products and services accordingly.",
|
| 46 |
+
interpretation = "default",
|
| 47 |
+
examples = [["I was extremely disappointed with this product. The quality was terrible and it broke after only a few days of use. Customer service was unhelpful and unresponsive. I would not recommend this product to anyone.", "This product was great! My family and I found it very useful."]]
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
app.launch()
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastai
|
| 2 |
+
gensim
|
| 3 |
+
gradio
|
| 4 |
+
ipywidgets
|
| 5 |
+
jupyter
|
| 6 |
+
nltk
|
| 7 |
+
notebook
|
| 8 |
+
pandas
|
| 9 |
+
plotly
|
| 10 |
+
pytest
|
| 11 |
+
scikit-learn
|
| 12 |
+
seaborn
|
| 13 |
+
setuptools
|
| 14 |
+
simpletransformers
|
| 15 |
+
spacy
|
| 16 |
+
transformers
|
| 17 |
+
wheel
|