Jayabalambika commited on
Commit
fd886b3
Β·
1 Parent(s): 64eb9a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -20
app.py CHANGED
@@ -9,6 +9,7 @@ import gradio as gr
9
  import matplotlib.pyplot as plt
10
  from skops import hub_utils
11
  import pickle
 
12
 
13
 
14
 
@@ -37,25 +38,22 @@ def visualize_input_data():
37
  # plt.show()
38
  return fig
39
 
40
- def download_model_skops():
41
- repo_id="sklearn-docs/anomaly-detection"
42
- download_repo = "downloaded-model"
43
- hub_utils.download(repo_id=repo_id, dst=download_repo)
44
- # repo_copy = mkdtemp(prefix="skops")
45
- # hub_utils.download(repo_id=repo_id, dst=repo_copy, token=token)
46
- # print(os.listdir(download_repo))
47
 
48
 
49
  from sklearn.inspection import DecisionBoundaryDisplay
50
 
51
- def plot_decision_boundary(classifier):
 
 
 
52
  disp = DecisionBoundaryDisplay.from_estimator(
53
- classifier,
54
  X,
55
  response_method="predict",
56
  alpha=0.5,
57
  )
58
- fig = plt.figure(1, facecolor="w", figsize=(5, 5))
59
  scatter = plt.scatter(X[:, 0], X[:, 1], c=y, s=20, edgecolor="k")
60
  disp.ax_.scatter(X[:, 0], X[:, 1], c=y, s=20, edgecolor="k")
61
  handles, labels = scatter.legend_elements()
@@ -64,7 +62,8 @@ def plot_decision_boundary(classifier):
64
 
65
  plt.legend(handles=handles, labels=["outliers", "inliers"], title="true class")
66
  # plt.savefig('decision_boundary.png',dpi=300, bbox_inches = "tight")
67
- return fig
 
68
 
69
 
70
 
@@ -80,22 +79,20 @@ with gr.Blocks(title=title) as demo:
80
 
81
  btn = gr.Button(value="Visualize input dataset")
82
  btn.click(visualize_input_data, outputs= gr.Plot(label='Visualizing input dataset') )
 
83
  # download
84
  repo_id="sklearn-docs/anomaly-detection"
85
  download_repo = "downloaded-model"
86
  hub_utils.download(repo_id=repo_id, dst=download_repo)
87
- if os.listdir(download_repo):
88
- # hub_utils.download(repo_id=repo_id, dst=download_repo)
89
-
90
 
 
91
 
92
-
93
- # print("Empty directory")
94
 
95
- # print(os.listdir(download_repo))
96
- loaded_model = pickle.load(open('isolation_forest.pkl', 'rb'))
97
- btn = gr.Button(value="Plot decision boundary")
98
- btn.click(plot_decision_boundary, inputs=[loaded_model], outputs= gr.Plot(label='Visualizing input dataset') )
 
99
 
100
 
101
  gr.Markdown( f"## Success")
 
9
  import matplotlib.pyplot as plt
10
  from skops import hub_utils
11
  import pickle
12
+ import time
13
 
14
 
15
 
 
38
  # plt.show()
39
  return fig
40
 
41
+
 
 
 
 
 
 
42
 
43
 
44
  from sklearn.inspection import DecisionBoundaryDisplay
45
 
46
+ def plot_decision_boundary():
47
+
48
+ time.sleep(1)
49
+
50
  disp = DecisionBoundaryDisplay.from_estimator(
51
+ loaded_model,
52
  X,
53
  response_method="predict",
54
  alpha=0.5,
55
  )
56
+ fig1 = plt.figure(1, facecolor="w", figsize=(5, 5))
57
  scatter = plt.scatter(X[:, 0], X[:, 1], c=y, s=20, edgecolor="k")
58
  disp.ax_.scatter(X[:, 0], X[:, 1], c=y, s=20, edgecolor="k")
59
  handles, labels = scatter.legend_elements()
 
62
 
63
  plt.legend(handles=handles, labels=["outliers", "inliers"], title="true class")
64
  # plt.savefig('decision_boundary.png',dpi=300, bbox_inches = "tight")
65
+
66
+ return fig1
67
 
68
 
69
 
 
79
 
80
  btn = gr.Button(value="Visualize input dataset")
81
  btn.click(visualize_input_data, outputs= gr.Plot(label='Visualizing input dataset') )
82
+
83
  # download
84
  repo_id="sklearn-docs/anomaly-detection"
85
  download_repo = "downloaded-model"
86
  hub_utils.download(repo_id=repo_id, dst=download_repo)
 
 
 
87
 
88
+ time.sleep(2)
89
 
 
 
90
 
91
+
92
+ print(os.listdir(download_repo))
93
+ loaded_model = pickle.load(open('./downloaded-model/isolation_forest.pkl', 'rb'))
94
+ btn_decision = gr.Button(value="Plot decision boundary")
95
+ btn_decision.click(plot_decision_boundary, outputs= gr.Plot(label='Plot decision boundary') )
96
 
97
 
98
  gr.Markdown( f"## Success")