Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,12 +6,11 @@ import matplotlib.pyplot as plt
|
|
| 6 |
from sklearn import svm
|
| 7 |
import gradio as gr
|
| 8 |
import matplotlib
|
| 9 |
-
|
| 10 |
|
| 11 |
kernels = ["linear", "poly", "rbf"]
|
| 12 |
|
| 13 |
-
font1 = {'family':'
|
| 14 |
-
|
| 15 |
|
| 16 |
cmaps = {'Set1': plt.cm.Set1, 'Set2': plt.cm.Set2, 'Set3': plt.cm.Set3,
|
| 17 |
'tab10': plt.cm.tab10, 'tab20': plt.cm.tab20}
|
|
@@ -99,7 +98,7 @@ def clf_kernel(kernel, cmap, dpi = 300, use_random = False):
|
|
| 99 |
|
| 100 |
return fig
|
| 101 |
|
| 102 |
-
intro = """<h1 style="text-align: center;">Introducing
|
| 103 |
"""
|
| 104 |
desc = """<h3 style="text-align: center;">🤗 Three different types of SVM-Kernels are displayed below.
|
| 105 |
The polynomial and RBF are especially useful when the data-points are not linearly separable. 🤗</h3>
|
|
@@ -116,22 +115,21 @@ Demo is based on this script from scikit-learn documentation</a>"""
|
|
| 116 |
|
| 117 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo",
|
| 118 |
secondary_hue="violet",
|
| 119 |
-
neutral_hue="
|
| 120 |
font = gr.themes.GoogleFont("Inter")),
|
| 121 |
title="SVM-Kernels") as demo:
|
| 122 |
gr.HTML(intro)
|
| 123 |
gr.HTML(desc)
|
| 124 |
with gr.Box():
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
show_label = True, value = 'linear')
|
| 128 |
with gr.Accordion(label = "More options", open = True):
|
| 129 |
cmap = gr.Radio(['Set1', 'Set2', 'Set3', 'tab10', 'tab20'], label="Choose color map: ", value = 'Set2')
|
| 130 |
dpi = gr.Slider(50, 150, value = 100, step = 1, label = "Set the resolution: ")
|
| 131 |
gr.HTML(notice)
|
| 132 |
random = gr.Checkbox(label="Randomize data", value = False)
|
| 133 |
|
| 134 |
-
|
| 135 |
plot = gr.Plot(label="Plot")
|
| 136 |
btn.click(fn=clf_kernel, inputs=[kernel,cmap,dpi,random], outputs=plot)
|
| 137 |
gr.HTML(made)
|
|
|
|
| 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}
|
|
|
|
| 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>
|
|
|
|
| 115 |
|
| 116 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo",
|
| 117 |
secondary_hue="violet",
|
| 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)
|