Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import sklearn
|
| 2 |
from os import O_ACCMODE
|
| 3 |
import gradio as gr
|
| 4 |
import joblib
|
|
@@ -41,15 +41,18 @@ def get_metadata(model_id):
|
|
| 41 |
except requests.exceptions.HTTPError:
|
| 42 |
return None
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
with app:
|
| 55 |
gr.Markdown(
|
|
@@ -76,8 +79,8 @@ with app:
|
|
| 76 |
with gr.Row():
|
| 77 |
out_1 = gr.Textbox(label="Prediction for Model 1")
|
| 78 |
|
| 79 |
-
classifier = pipeline("text-classification", model
|
| 80 |
-
btn1.click(fn=
|
| 81 |
|
| 82 |
gr.Markdown(
|
| 83 |
"""
|
|
@@ -89,6 +92,6 @@ with app:
|
|
| 89 |
with gr.Row():
|
| 90 |
out_2 = gr.Textbox(label="Prediction for Model 2")
|
| 91 |
classifier = pipeline("text-classification", model=model_id_2)
|
| 92 |
-
btn2.click(fn=
|
| 93 |
|
| 94 |
app.launch()
|
|
|
|
| 1 |
+
# import sklearn
|
| 2 |
from os import O_ACCMODE
|
| 3 |
import gradio as gr
|
| 4 |
import joblib
|
|
|
|
| 41 |
except requests.exceptions.HTTPError:
|
| 42 |
return None
|
| 43 |
|
| 44 |
+
def get_prediction(model_id):
|
| 45 |
+
|
| 46 |
+
classifier = pipeline("text-classification", model=model_id)
|
| 47 |
+
|
| 48 |
+
def predict(review):
|
| 49 |
+
prediction = classifier(review)
|
| 50 |
+
print(prediction)
|
| 51 |
+
stars = prediction[0]['label']
|
| 52 |
+
stars = (int)(stars.split('_')[1])+1
|
| 53 |
+
score = 100*prediction[0]['score']
|
| 54 |
+
return "{} {:.0f}%".format("\U00002B50"*stars, score)
|
| 55 |
+
return predict
|
| 56 |
|
| 57 |
with app:
|
| 58 |
gr.Markdown(
|
|
|
|
| 79 |
with gr.Row():
|
| 80 |
out_1 = gr.Textbox(label="Prediction for Model 1")
|
| 81 |
|
| 82 |
+
# classifier = pipeline("text-classification", model)
|
| 83 |
+
btn1.click(fn=get_prediction(model_id_1), inputs=inp_1, outputs=out_1)
|
| 84 |
|
| 85 |
gr.Markdown(
|
| 86 |
"""
|
|
|
|
| 92 |
with gr.Row():
|
| 93 |
out_2 = gr.Textbox(label="Prediction for Model 2")
|
| 94 |
classifier = pipeline("text-classification", model=model_id_2)
|
| 95 |
+
btn2.click(fn=get_prediction(model_id_2), inputs=inp_1, outputs=out_2)
|
| 96 |
|
| 97 |
app.launch()
|