Raaniel commited on
Commit
03ab24e
·
1 Parent(s): 70535d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -17
app.py CHANGED
@@ -5,12 +5,11 @@ import numpy as np
5
  import matplotlib.pyplot as plt
6
  from sklearn import svm
7
  import gradio as gr
8
- import matplotlib
9
  plt.switch_backend("agg")
10
 
11
  kernels = ["linear", "poly", "rbf"]
12
 
13
- font1 = {'family':'Comic Sans SM','size':20}
14
 
15
  cmaps = {'Set1': plt.cm.Set1, 'Set2': plt.cm.Set2, 'Set3': plt.cm.Set3,
16
  'tab10': plt.cm.tab10, 'tab20': plt.cm.tab20}
@@ -96,15 +95,16 @@ def clf_kernel(kernel, cmap, dpi = 300, use_random = False):
96
  bbox=dict(boxstyle="round,pad=0.3",
97
  color = "#6366F1"))
98
 
 
99
  return fig
100
 
101
- intro = """<h1 style="text-align: center;">Introducing SVM-Kernels</h1>
102
  """
103
- desc = """<h3 style="text-align: center;">🤗 Three different types of SVM-Kernels are displayed below.
104
- The polynomial and RBF are especially useful when the data-points are not linearly separable. 🤗</h3>
105
  """
106
- notice = """<div style = "text-align: left;"> <em>Notice: Run the model on example data or check
107
- <strong>Randomize data</strong> to check out the model on emulated data-points.</em></div>"""
108
 
109
  made ="""<div style="text-align: center;">
110
  <p>Made with ❤</p>"""
@@ -118,20 +118,27 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo",
118
  neutral_hue="slate",
119
  font = gr.themes.GoogleFont("Inter")),
120
  title="SVM-Kernels") as demo:
 
121
  gr.HTML(intro)
122
  gr.HTML(desc)
123
- with gr.Box():
124
- kernel = gr.Dropdown([i for i in kernels], label="Select kernel:",
125
  show_label = True, value = 'linear')
126
- with gr.Accordion(label = "More options", open = True):
127
- cmap = gr.Radio(['Set1', 'Set2', 'Set3', 'tab10', 'tab20'], label="Choose color map: ", value = 'Set2')
128
- dpi = gr.Slider(50, 150, value = 100, step = 1, label = "Set the resolution: ")
129
- gr.HTML(notice)
130
- random = gr.Checkbox(label="Randomize data", value = False)
 
 
131
 
132
- btn = gr.Button('Make plot!').style(full_width=True)
133
- plot = gr.Plot(label="Plot")
134
- btn.click(fn=clf_kernel, inputs=[kernel,cmap,dpi,random], outputs=plot)
 
 
 
 
135
  gr.HTML(made)
136
  gr.HTML(link)
137
 
 
5
  import matplotlib.pyplot as plt
6
  from sklearn import svm
7
  import gradio as gr
 
8
  plt.switch_backend("agg")
9
 
10
  kernels = ["linear", "poly", "rbf"]
11
 
12
+ font1 = {'family':'DejaVu Sans','size':20}
13
 
14
  cmaps = {'Set1': plt.cm.Set1, 'Set2': plt.cm.Set2, 'Set3': plt.cm.Set3,
15
  'tab10': plt.cm.tab10, 'tab20': plt.cm.tab20}
 
95
  bbox=dict(boxstyle="round,pad=0.3",
96
  color = "#6366F1"))
97
 
98
+ plt.close()
99
  return fig
100
 
101
+ intro = """<h1 style="text-align: center;">🤗 Introducing SVM-Kernels 🤗</h1>
102
  """
103
+ desc = """<h3 style="text-align: center;">Three different types of SVM-Kernels are displayed below.
104
+ The polynomial and RBF are especially useful when the data-points are not linearly separable. </h3>
105
  """
106
+ notice = """<div style = "text-align: left;"> <em>Notice: Run the model on example data or press
107
+ <strong>Randomize data</strong> button to check out the model on emulated data-points.</em></div>"""
108
 
109
  made ="""<div style="text-align: center;">
110
  <p>Made with ❤</p>"""
 
118
  neutral_hue="slate",
119
  font = gr.themes.GoogleFont("Inter")),
120
  title="SVM-Kernels") as demo:
121
+
122
  gr.HTML(intro)
123
  gr.HTML(desc)
124
+ with gr.Column():
125
+ kernel = gr.Radio(kernels, label="Select kernel:",
126
  show_label = True, value = 'linear')
127
+ plot = gr.Plot(label="Plot")
128
+
129
+ with gr.Accordion(label = "More options", open = True):
130
+ cmap = gr.Radio(['Set1', 'Set2', 'Set3', 'tab10', 'tab20'], label="Choose color map: ", value = 'Set2')
131
+ dpi = gr.Slider(50, 150, value = 100, step = 1, label = "Set the resolution: ")
132
+ gr.HTML(notice)
133
+ random = gr.Button("Randomize data").style(full_width = False)
134
 
135
+ cmap.change(fn=clf_kernel, inputs=[kernel,cmap,dpi], outputs=plot)
136
+ dpi.change(fn=clf_kernel, inputs=[kernel,cmap,dpi], outputs=plot)
137
+ kernel.change(fn=clf_kernel, inputs=[kernel,cmap,dpi], outputs=plot)
138
+
139
+ random.click(fn=clf_kernel, inputs=[kernel,cmap,dpi,random], outputs=plot)
140
+
141
+ demo.load(fn=clf_kernel, inputs=[kernel,cmap,dpi], outputs=plot)
142
  gr.HTML(made)
143
  gr.HTML(link)
144