Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,21 @@
|
|
| 1 |
import pandas as pd
|
| 2 |
import pickle as pkl
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from numpy import reshape
|
| 4 |
import numpy as np
|
| 5 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
class NLP:
|
|
@@ -71,11 +84,11 @@ class NLP:
|
|
| 71 |
return(tmp, str(self.__perceptron_rat_score))
|
| 72 |
|
| 73 |
def kneighbors_pol_eval(self, evalu):
|
| 74 |
-
return ([0, 0], "0.45")
|
| 75 |
#return(self.__k_neighbors_pol.predict_proba(evalu).tolist(), str(self.__k_neighbors_rat_score))
|
| 76 |
|
| 77 |
def kneighbors_rat_eval(self, evalu):
|
| 78 |
-
return ([0, 0], "0.27")
|
| 79 |
#return(self.__k_neighbors_rat.predict_proba(evalu).tolist(), str(self.__k_neighbors_rat_score))
|
| 80 |
|
| 81 |
def NB_pol_eval(self, evalu):
|
|
@@ -85,11 +98,11 @@ class NLP:
|
|
| 85 |
return(self.__nb_rat.predict_proba(evalu).tolist(), str(self.__nb_rat_score))
|
| 86 |
|
| 87 |
def SVM_pol_eval(self, evalu):
|
| 88 |
-
return ([0, 0], "0.57")
|
| 89 |
#return(self.__svm_pol.predict_proba(evalu).tolist(), str(self.__svm_pol_score))
|
| 90 |
|
| 91 |
def SVM_rat_eval(self, evalu):
|
| 92 |
-
return ([0, 0], "0.22")
|
| 93 |
#return(self.__svm_rat.predict_proba(evalu).tolist(), str(self.__svm_rat_score))
|
| 94 |
|
| 95 |
def RF_pol_eval(self, evalu):
|
|
@@ -130,8 +143,10 @@ class NLP:
|
|
| 130 |
percent, score = self.__exec[model][1](review)
|
| 131 |
res = pd.DataFrame({'Rated 1/5': percent[0][0], 'Rated 2/5': percent[0][1], 'Rated 4/5': percent[0][2], 'Rated 5/5': percent[0][3]}, index=["Prediction"])
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
| 135 |
|
| 136 |
if __name__ == "__main__":
|
| 137 |
class Execution:
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
import pickle as pkl
|
| 3 |
+
from sklearn.preprocessing import StandardScaler
|
| 4 |
+
from sklearn.model_selection import train_test_split
|
| 5 |
+
from sklearn.dummy import DummyClassifier
|
| 6 |
+
from sklearn.feature_extraction.text import CountVectorizer
|
| 7 |
+
from sklearn.linear_model import Perceptron
|
| 8 |
from numpy import reshape
|
| 9 |
import numpy as np
|
| 10 |
+
from sklearn.metrics import accuracy_score
|
| 11 |
+
from sklearn.metrics import classification_report
|
| 12 |
+
from sklearn.naive_bayes import GaussianNB
|
| 13 |
+
from sklearn.neighbors import KNeighborsClassifier
|
| 14 |
+
from sklearn.linear_model import Perceptron
|
| 15 |
+
from sklearn.dummy import DummyClassifier
|
| 16 |
+
from sklearn.ensemble import RandomForestClassifier
|
| 17 |
+
from sklearn.neural_network import MLPClassifier
|
| 18 |
+
from sklearn import svm
|
| 19 |
import gradio as gr
|
| 20 |
|
| 21 |
class NLP:
|
|
|
|
| 84 |
return(tmp, str(self.__perceptron_rat_score))
|
| 85 |
|
| 86 |
def kneighbors_pol_eval(self, evalu):
|
| 87 |
+
return ([[0, 0]], "0.45")
|
| 88 |
#return(self.__k_neighbors_pol.predict_proba(evalu).tolist(), str(self.__k_neighbors_rat_score))
|
| 89 |
|
| 90 |
def kneighbors_rat_eval(self, evalu):
|
| 91 |
+
return ([[0, 0]], "0.27")
|
| 92 |
#return(self.__k_neighbors_rat.predict_proba(evalu).tolist(), str(self.__k_neighbors_rat_score))
|
| 93 |
|
| 94 |
def NB_pol_eval(self, evalu):
|
|
|
|
| 98 |
return(self.__nb_rat.predict_proba(evalu).tolist(), str(self.__nb_rat_score))
|
| 99 |
|
| 100 |
def SVM_pol_eval(self, evalu):
|
| 101 |
+
return ([[0, 0]], "0.57")
|
| 102 |
#return(self.__svm_pol.predict_proba(evalu).tolist(), str(self.__svm_pol_score))
|
| 103 |
|
| 104 |
def SVM_rat_eval(self, evalu):
|
| 105 |
+
return ([[0, 0]], "0.22")
|
| 106 |
#return(self.__svm_rat.predict_proba(evalu).tolist(), str(self.__svm_rat_score))
|
| 107 |
|
| 108 |
def RF_pol_eval(self, evalu):
|
|
|
|
| 143 |
percent, score = self.__exec[model][1](review)
|
| 144 |
res = pd.DataFrame({'Rated 1/5': percent[0][0], 'Rated 2/5': percent[0][1], 'Rated 4/5': percent[0][2], 'Rated 5/5': percent[0][3]}, index=["Prediction"])
|
| 145 |
|
| 146 |
+
if (percent[0][0] == 0 and percent[1][0] == 0):
|
| 147 |
+
return (res, f"Model: {model}\nDataset: {Dataset}\nAccuracy: {str(float(score)*100)}\nDue to the size of the model, it has not been implemented on huggingface.")
|
| 148 |
+
else:
|
| 149 |
+
return (res, f"Model: {model}\nDataset: {Dataset}\nAccuracy: {str(float(score)*100)}")
|
| 150 |
|
| 151 |
if __name__ == "__main__":
|
| 152 |
class Execution:
|