CK42 commited on
Commit
db66b47
1 Parent(s): e4fa88d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
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
- classifier = pipeline("text-classification", model)
45
-
46
- def predict(review):
47
- prediction = classifier(review)
48
- print(prediction)
49
- stars = prediction[0]['label']
50
- stars = (int)(stars.split('_')[1])+1
51
- score = 100*prediction[0]['score']
52
- return "{} {:.0f}%".format("\U00002B50"*stars, score)
 
 
 
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=model_id_1)
80
- btn1.click(fn=predict, inputs=inp_1, outputs=out_1)
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=predict, inputs=inp_1, outputs=out_2)
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()