demomern's picture
Update app.py
c183877
raw
history blame contribute delete
No virus
6.58 kB
import re
import emoji
import joblib
from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer
from sklearn.neural_network import MLPClassifier
from sklearn.preprocessing import LabelEncoder
from sklearn.metrics import classification_report, accuracy_score, confusion_matrix, f1_score
import gradio as gr
# load the TF-IDF vectorizer to a file
cv = joblib.load('tfidf_vectorizer.pkl')
# load the MLP classifier to a file
mlp_label = joblib.load('mlpLabel.pkl')
# load the MLP Aspect classifier to a file
mlp_aspect_label = joblib.load('mlpAspectLabel.pkl')
def remove_html(text) :
patt_html = r"<.*?>"
text = re.sub(patt_html, "", text)
return text
def remove_url(text):
patt_url = r"https?://\S+|www\.\S+"
text = re.sub(patt_url, "", text)
return text
def emoji_to_text(text) :
res_str = ""
for ch in text :
if emoji.is_emoji(ch) :
res_str += f" {emoji.demojize(ch)} "
# print(ch, emoji.demojize(ch))
else :
res_str += ch
return res_str
def clean_review_text(text):
# remove HTML Tags
text = remove_html(text)
# remove url to call function remover_url
text = remove_url(text)
# convert text emoji into text
text = emoji_to_text(text)
# convert all text into lower case
text = text.lower()
return text
label = ['negative', 'neutral', 'positive']
aspect_label = ['Card Decks and Challenges', 'Card Play and Board Games',
'Fun and Coin Collecting', 'Game Scores and Features',
'Game Updates and User Desires', 'Gameplay and App Experience',
'Gameplay and Trading', 'Gameplay and User Experience',
'Property and Land Management', 'Subway Adventures']
def return_label_aspect(Review):
review_vec = cv.transform([clean_review_text(Review)])
pred_label = mlp_label.predict_proba(review_vec)[0]
pred_aspect = mlp_aspect_label.predict_proba(review_vec)[0]
pred_label = { label[i]: round(pred_label[i], 2) for i in range(3) }
pred_aspect = { aspect_label[i]: round(pred_aspect[i], 2) for i in range(10) }
return pred_label, pred_aspect
iface = gr.Interface(
fn=return_label_aspect,
inputs="text",
outputs=[gr.Label(), gr.Label()],
examples=[
"app is very good",
"app is very bad",
"This new version of Things has an entirely different aesthetic from Things 2. Things 2 is much more minimalist; Things 3 seems to have a lot of UI bloat. Not quite sure where the design award came from.",
"cI have been using this app for over 3 years now and it has proven over and over again to deliver. My strongest uses are:+ In my profession as a elite level coach; class and calendar planning , documents that my athletes need signed and emailed, this app has it all in one.+ construction;2 years ago I started building my house, and this app has delivered over my expectations in my to do’s and project management. I have used it at every step of my construction, from having my blue prints always ready and on hand, zooming the blue prints where I need to show the builder modifications and additions, recording all inspection approvals, and even walking my electrician, plumber and low Voltage cable technician through all the spots in my house I wanted my light features / facets / TV, speakers, and cat cables connections to be. All those contractors were blown away by how easy and quick we both were on the same page. Later on, I just emailed each one of them a pdf version of the drawings we agreed on and there were no hiccups anywhere.I have even used it to show my painter what trims go which colors.+ family, household, and my non-profit board of directors at work, I ah e it all in this app.Everything organized in files and folders..., I cannot even start to think all the apps I would need to keep my life organized without Notability. Great product.",
"A lot of people use word because its very standard. But I run into the same problem when I use it. Every update there’s a problem with the format. Everything that I had on page 2, is now partly on page 1. And what I had on part 3, is partly on page 2, and so forth, throughout all 200+pages of my document. Try to call for support and reach someone who barely speaks English. I tell them what happens, and they say “so is it because you changed something in your document”? Yes, when I closed my document yesterday, it was formatted correctly. Then after I updated the app today, and opened it up and it was wrong, it must have been when I did it in the middle of the night.I will be switching to Apples pages. Thanks for the people who work really hard to make this work, it really is a great effort for the most part. But it’s just not fun doing this when the issue happens on my MacBook and my iPad. What’s the point of setting something up to be exactly how you want it, if a simple update changes everything? It’s nonsense.",
"This used to be my go to app for note taking. But for over a year now I have had problems with writing while using the recording feature. I even bought a brand new iPad Pro because I though it was the device space causing this issue it turns out I was wrong. They have issues with their iCloud syncing that they even a year later have not fixed. While writing and recording it will cause a syncing messages to come up while your using it making it unusable while it does that. You are missing what you want to record and unable to write turning that time. Even when it finishes syncing it will do it again a few minutes later once again interrupting you. I have tried everything recommended nothing worked. I even freshly installed my iPad with only this application and even on my new iPad Pro it did the same thing and it has 64gb of space and nothing else on it. I’m disappointed that even after a year they have not solved their problems do not waste your money on this app. Especially when the one feature that is supposed to make it more enticing then GoodNotes doesn’t even work.",
"I use it for years. It’s tagging capability is unique. It’s integration across all platforms is the same. It’s ability to annotate pdf files is very useful. Same for its integration with all browsers. It is a great product. I am a paying customers for years. I hope company does well and has resources to keep updating it.",
]
)
# iface = gr.Interface(fn=return_label_aspect, inputs="text", outputs=[gr.Label(), gr.Label()])
iface.launch(inline = False)