n1kkqt commited on
Commit
88a1691
1 Parent(s): fb28f73

Add multiple class functionality

Browse files
Files changed (2) hide show
  1. app.py +4 -47
  2. app2.py +50 -0
app.py CHANGED
@@ -1,50 +1,7 @@
1
  import gradio as gr
2
- from xdog import to_sketch
3
- from model import Generator, ResNeXtBottleneck
4
- import torch
5
- from data_utils import *
6
- import glob
7
- gen = torch.load('model/model.pth')
8
 
9
- def convert_to_lineart(img, sigma, k, gamma, epsilon, phi, area_min):
10
- phi = 10 * phi
11
- out = to_sketch(img, sigma=sigma, k=k, gamma=gamma, epsilon=epsilon, phi=phi, area_min=area_min)
12
- return out
13
 
14
- def inference(sk):
15
- return predict_img(gen, sk, hnt = None)
16
-
17
- title = "To Line Art"
18
- description = "Line art colorization showcase. "
19
- article = "Github Repo"
20
-
21
- with gr.Blocks() as demo:
22
- with gr.Row():
23
- with gr.Column():
24
- image = gr.Image(type="pil", value='examples/Genshin-Impact-anime.jpg')
25
- to_lineart_button = gr.Button("To Lineart")
26
-
27
- gr.Examples(
28
- examples=glob.glob('examples/*.jpg'),
29
- inputs=image,
30
- outputs=image,
31
- fn=None,
32
- cache_examples=False,
33
- )
34
-
35
- with gr.Column():
36
- sigma = gr.Slider(0.1, 0.5, value=0.3, step=0.1, label='σ')
37
- k = gr.Slider(1.0, 8.0, value=4.5, step=0.5, label='k')
38
- gamma = gr.Slider(0.05, 1.0, value=0.95, step=0.05, label='γ')
39
- epsilon = gr.Slider(-2, 2, value=-1, step=0.5, label='ε')
40
- phi = gr.Slider(10, 20, label = 'φ', value=15)
41
- min_area = gr.Slider(1, 5, value=2, step=1, label='Minimal Area')
42
-
43
- with gr.Column():
44
- lineart = gr.Image(type="pil", image_mode='L')
45
- inpaint_button = gr.Button("Inpaint")
46
-
47
- to_lineart_button.click(convert_to_lineart, inputs=[image, sigma, k, gamma, epsilon, phi, min_area], outputs=lineart)
48
- inpaint_button.click(inference, inputs=lineart, outputs=lineart)
49
-
50
- demo.launch()
 
1
  import gradio as gr
 
 
 
 
 
 
2
 
3
+ def greet(name):
4
+ return "Hello " + name + "!!"
 
 
5
 
6
+ iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
+ iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app2.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from xdog import to_sketch
3
+ from model import Generator, ResNeXtBottleneck
4
+ import torch
5
+ from data_utils import *
6
+ import glob
7
+ gen = torch.load('model/model.pth')
8
+
9
+ def convert_to_lineart(img, sigma, k, gamma, epsilon, phi, area_min):
10
+ phi = 10 * phi
11
+ out = to_sketch(img, sigma=sigma, k=k, gamma=gamma, epsilon=epsilon, phi=phi, area_min=area_min)
12
+ return out
13
+
14
+ def inference(sk):
15
+ return predict_img(gen, sk, hnt = None)
16
+
17
+ title = "To Line Art"
18
+ description = "Line art colorization showcase. "
19
+ article = "Github Repo"
20
+
21
+ with gr.Blocks() as demo:
22
+ with gr.Row():
23
+ with gr.Column():
24
+ image = gr.Image(type="pil", value='examples/Genshin-Impact-anime.jpg')
25
+ to_lineart_button = gr.Button("To Lineart")
26
+
27
+ gr.Examples(
28
+ examples=glob.glob('examples/*.jpg'),
29
+ inputs=image,
30
+ outputs=image,
31
+ fn=None,
32
+ cache_examples=False,
33
+ )
34
+
35
+ with gr.Column():
36
+ sigma = gr.Slider(0.1, 0.5, value=0.3, step=0.1, label='σ')
37
+ k = gr.Slider(1.0, 8.0, value=4.5, step=0.5, label='k')
38
+ gamma = gr.Slider(0.05, 1.0, value=0.95, step=0.05, label='γ')
39
+ epsilon = gr.Slider(-2, 2, value=-1, step=0.5, label='ε')
40
+ phi = gr.Slider(10, 20, label = 'φ', value=15)
41
+ min_area = gr.Slider(1, 5, value=2, step=1, label='Minimal Area')
42
+
43
+ with gr.Column():
44
+ lineart = gr.Image(type="pil", image_mode='L')
45
+ inpaint_button = gr.Button("Inpaint")
46
+
47
+ to_lineart_button.click(convert_to_lineart, inputs=[image, sigma, k, gamma, epsilon, phi, min_area], outputs=lineart)
48
+ inpaint_button.click(inference, inputs=lineart, outputs=lineart)
49
+
50
+ demo.launch()