Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -15,6 +15,15 @@ model_id_3 = "distilbert-base-uncased-finetuned-sst-2-english"
|
|
15 |
model_id_4 = "lordtt13/emo-mobilebert"
|
16 |
model_id_5 = "juliensimon/reviews-sentiment-analysis"
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
def get_prediction(model_id):
|
19 |
|
20 |
classifier = pipeline("text-classification", model=model_id, return_all_scores=True)
|
@@ -22,7 +31,7 @@ def get_prediction(model_id):
|
|
22 |
def predict(review):
|
23 |
prediction = classifier(review)
|
24 |
print(prediction)
|
25 |
-
return prediction
|
26 |
return predict
|
27 |
|
28 |
with app:
|
|
|
15 |
model_id_4 = "lordtt13/emo-mobilebert"
|
16 |
model_id_5 = "juliensimon/reviews-sentiment-analysis"
|
17 |
|
18 |
+
def parse_output(output_json): # list of list of dicts
|
19 |
+
list_pred=[]
|
20 |
+
for i in range(len(output_json[0])):
|
21 |
+
label = output_json[0][i]['label']
|
22 |
+
score = output_json[0][i]['score']
|
23 |
+
list_pred.append((label, score))
|
24 |
+
return list_pred
|
25 |
+
|
26 |
+
|
27 |
def get_prediction(model_id):
|
28 |
|
29 |
classifier = pipeline("text-classification", model=model_id, return_all_scores=True)
|
|
|
31 |
def predict(review):
|
32 |
prediction = classifier(review)
|
33 |
print(prediction)
|
34 |
+
return parse_output(prediction)
|
35 |
return predict
|
36 |
|
37 |
with app:
|