CK42 commited on
Commit
0997d43
1 Parent(s): 75f1b92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -30
app.py CHANGED
@@ -1,3 +1,7 @@
 
 
 
 
1
  from os import O_ACCMODE
2
  import gradio as gr
3
  import joblib
@@ -6,45 +10,25 @@ import requests.exceptions
6
  from huggingface_hub import HfApi, hf_hub_download
7
  from huggingface_hub.repocard import metadata_load
8
 
9
- # work around for error, not happy really
10
- # import os
11
- # os.environ['KMP_DUPLICATE_LIB_OK']='True'
12
 
13
  app = gr.Blocks()
14
 
15
- model_1 = "juliensimon/distilbert-amazon-shoe-reviews"
16
- model_2 = "juliensimon/distilbert-amazon-shoe-reviews"
17
 
18
- def load_agent(model_id_1, model_id_2):
19
  """
20
  This function load the agent's results
21
  """
22
  # Load the metrics
23
- metadata_1 = get_metadata(model_id_1)
24
 
25
  # get predictions
26
- predictions_1 = predict(model_id_1)
27
-
28
- # Get the accuracy
29
- # results_1 = parse_metrics_accuracy(metadata_1)
30
-
31
- # Load the metrics
32
- metadata_2 = get_metadata(model_id_2)
33
 
34
- # get predictions
35
- predictions_2 = predict(model_id_2)
36
- # Get the accuracy
37
- # results_2 = parse_metrics_accuracy(metadata_2)
38
 
39
- return model_id_1, predictions_1, model_id_2, predictions_2
40
 
41
- # def parse_metrics_accuracy(meta):
42
- # if "model-index" not in meta:
43
- # return None
44
- # result = meta["model-index"][0]["results"]
45
- # metrics = result[0]["metrics"]
46
- # accuracy = metrics[0]["value"]
47
- # return accuracy
48
 
49
  def get_metadata(model_id):
50
  """
@@ -91,7 +75,7 @@ with app:
91
  model1_input = gr.Textbox(label="Model 1")
92
  with gr.Row():
93
  btn = gr.Button("Prediction for Model 1")
94
- btn.click(fn=predict(model_1), inputs=inp_1, outputs=out_2)
95
 
96
 
97
 
@@ -99,13 +83,13 @@ with app:
99
  model2_input = gr.Textbox(label="Model 2")
100
  with gr.Row():
101
  btn = gr.Button("Prediction for Model 2")
102
- btn.click(fn=predict(model_2), inputs=inp_1, outputs=out_2)
103
 
104
 
105
- app_button.click(load_agent, inputs=[model1_input, model2_input], outputs=[model1_name, model1_score_output, model2_name, model2_score_output])
106
 
107
  # examples = gr.Examples(examples=[["juliensimon/distilbert-amazon-shoe-reviews","juliensimon/distilbert-amazon-shoe-reviews"]],
108
  # inputs=[model1_input, model2_input])
109
 
110
 
111
- app.launch()
 
1
+
2
+ # https://huggingface.co/spaces/CK42/sentiment-model-comparison/blob/main/app.py
3
+
4
+ # import sklearn
5
  from os import O_ACCMODE
6
  import gradio as gr
7
  import joblib
 
10
  from huggingface_hub import HfApi, hf_hub_download
11
  from huggingface_hub.repocard import metadata_load
12
 
 
 
 
13
 
14
  app = gr.Blocks()
15
 
16
+ model_id_1 = "juliensimon/distilbert-amazon-shoe-reviews"
17
+ model_id_2 = "juliensimon/distilbert-amazon-shoe-reviews"
18
 
19
+ def load_agent(model_id):
20
  """
21
  This function load the agent's results
22
  """
23
  # Load the metrics
24
+ metadata = get_metadata(model_id)
25
 
26
  # get predictions
27
+ predictions = predict(model_id)
 
 
 
 
 
 
28
 
 
 
 
 
29
 
30
+ return model_id, predictions
31
 
 
 
 
 
 
 
 
32
 
33
  def get_metadata(model_id):
34
  """
 
75
  model1_input = gr.Textbox(label="Model 1")
76
  with gr.Row():
77
  btn = gr.Button("Prediction for Model 1")
78
+ btn.click(fn=load_agent(model_id_1), inputs=inp_1, outputs=out_2)
79
 
80
 
81
 
 
83
  model2_input = gr.Textbox(label="Model 2")
84
  with gr.Row():
85
  btn = gr.Button("Prediction for Model 2")
86
+ btn.click(fn=predict(model_id_2), inputs=inp_1, outputs=out_2)
87
 
88
 
89
+ # app_button.click(load_agent, inputs=[model1_input, model2_input], outputs=[model1_name, model1_score_output, model2_name, model2_score_output])
90
 
91
  # examples = gr.Examples(examples=[["juliensimon/distilbert-amazon-shoe-reviews","juliensimon/distilbert-amazon-shoe-reviews"]],
92
  # inputs=[model1_input, model2_input])
93
 
94
 
95
+ app.launch()