awacke1 commited on
Commit
34dc422
ยท
1 Parent(s): d6a4f83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -18
app.py CHANGED
@@ -4,13 +4,11 @@ import torch.nn as nn
4
  import gradio as gr
5
  from PIL import Image
6
  import torchvision.transforms as transforms
7
-
8
  norm_layer = nn.InstanceNorm2d
9
 
10
  class ResidualBlock(nn.Module):
11
  def __init__(self, in_features):
12
  super(ResidualBlock, self).__init__()
13
-
14
  conv_block = [ nn.ReflectionPad2d(1),
15
  nn.Conv2d(in_features, in_features, 3),
16
  norm_layer(in_features),
@@ -19,9 +17,7 @@ class ResidualBlock(nn.Module):
19
  nn.Conv2d(in_features, in_features, 3),
20
  norm_layer(in_features)
21
  ]
22
-
23
  self.conv_block = nn.Sequential(*conv_block)
24
-
25
  def forward(self, x):
26
  return x + self.conv_block(x)
27
 
@@ -29,15 +25,11 @@ class ResidualBlock(nn.Module):
29
  class Generator(nn.Module):
30
  def __init__(self, input_nc, output_nc, n_residual_blocks=9, sigmoid=True):
31
  super(Generator, self).__init__()
32
-
33
- # Initial convolution block
34
  model0 = [ nn.ReflectionPad2d(3),
35
  nn.Conv2d(input_nc, 64, 7),
36
  norm_layer(64),
37
  nn.ReLU(inplace=True) ]
38
  self.model0 = nn.Sequential(*model0)
39
-
40
- # Downsampling
41
  model1 = []
42
  in_features = 64
43
  out_features = in_features*2
@@ -48,14 +40,10 @@ class Generator(nn.Module):
48
  in_features = out_features
49
  out_features = in_features*2
50
  self.model1 = nn.Sequential(*model1)
51
-
52
  model2 = []
53
- # Residual blocks
54
  for _ in range(n_residual_blocks):
55
  model2 += [ResidualBlock(in_features)]
56
  self.model2 = nn.Sequential(*model2)
57
-
58
- # Upsampling
59
  model3 = []
60
  out_features = in_features//2
61
  for _ in range(2):
@@ -65,13 +53,10 @@ class Generator(nn.Module):
65
  in_features = out_features
66
  out_features = in_features//2
67
  self.model3 = nn.Sequential(*model3)
68
-
69
- # Output layer
70
  model4 = [ nn.ReflectionPad2d(3),
71
  nn.Conv2d(64, output_nc, 7)]
72
  if sigmoid:
73
  model4 += [nn.Sigmoid()]
74
-
75
  self.model4 = nn.Sequential(*model4)
76
 
77
  def forward(self, x, cond=None):
@@ -80,7 +65,6 @@ class Generator(nn.Module):
80
  out = self.model2(out)
81
  out = self.model3(out)
82
  out = self.model4(out)
83
-
84
  return out
85
 
86
  model1 = Generator(3, 1, 3)
@@ -107,8 +91,8 @@ def predict(input_img, ver):
107
  drawing = transforms.ToPILImage()(drawing)
108
  return drawing
109
 
110
- title="Image to Line Drawings - Complex and Simple Portraits and Landscapes"
111
- description="Image to Line Drawing L4xKDhK7zqHtYRYptIOJ--N5LZB (1).mp4 "
112
  # article = "<p style='text-align: center'></p>"
113
  examples=[
114
  ['Achilles-art-scale-6_00x-gigapixel.png', 'Simple Lines'],
 
4
  import gradio as gr
5
  from PIL import Image
6
  import torchvision.transforms as transforms
 
7
  norm_layer = nn.InstanceNorm2d
8
 
9
  class ResidualBlock(nn.Module):
10
  def __init__(self, in_features):
11
  super(ResidualBlock, self).__init__()
 
12
  conv_block = [ nn.ReflectionPad2d(1),
13
  nn.Conv2d(in_features, in_features, 3),
14
  norm_layer(in_features),
 
17
  nn.Conv2d(in_features, in_features, 3),
18
  norm_layer(in_features)
19
  ]
 
20
  self.conv_block = nn.Sequential(*conv_block)
 
21
  def forward(self, x):
22
  return x + self.conv_block(x)
23
 
 
25
  class Generator(nn.Module):
26
  def __init__(self, input_nc, output_nc, n_residual_blocks=9, sigmoid=True):
27
  super(Generator, self).__init__()
 
 
28
  model0 = [ nn.ReflectionPad2d(3),
29
  nn.Conv2d(input_nc, 64, 7),
30
  norm_layer(64),
31
  nn.ReLU(inplace=True) ]
32
  self.model0 = nn.Sequential(*model0)
 
 
33
  model1 = []
34
  in_features = 64
35
  out_features = in_features*2
 
40
  in_features = out_features
41
  out_features = in_features*2
42
  self.model1 = nn.Sequential(*model1)
 
43
  model2 = []
 
44
  for _ in range(n_residual_blocks):
45
  model2 += [ResidualBlock(in_features)]
46
  self.model2 = nn.Sequential(*model2)
 
 
47
  model3 = []
48
  out_features = in_features//2
49
  for _ in range(2):
 
53
  in_features = out_features
54
  out_features = in_features//2
55
  self.model3 = nn.Sequential(*model3)
 
 
56
  model4 = [ nn.ReflectionPad2d(3),
57
  nn.Conv2d(64, output_nc, 7)]
58
  if sigmoid:
59
  model4 += [nn.Sigmoid()]
 
60
  self.model4 = nn.Sequential(*model4)
61
 
62
  def forward(self, x, cond=None):
 
65
  out = self.model2(out)
66
  out = self.model3(out)
67
  out = self.model4(out)
 
68
  return out
69
 
70
  model1 = Generator(3, 1, 3)
 
91
  drawing = transforms.ToPILImage()(drawing)
92
  return drawing
93
 
94
+ title="Art Style Line Drawings - Complex and Simple Portraits and Landscapes"
95
+ description="Art Style Line Drawings ๐Ÿฆ€๐Ÿฆ๐Ÿฆ‚๐Ÿฆƒ๐Ÿฆ„๐Ÿฆ…๐Ÿฆ†๐Ÿฆ‡๐Ÿฆˆ๐Ÿฆ‰๐ŸฆŠ๐Ÿฆ‹๐ŸฆŒ๐Ÿฆ๐ŸฆŽ๐Ÿฆ ๐Ÿฆ๐Ÿฆ‘๐Ÿฆ’๐Ÿฆ“๐Ÿฆ”๐Ÿฆ•๐Ÿฆ–๐Ÿฆ—๐Ÿฆ˜๐Ÿฆ™๐Ÿฆš๐Ÿฆ›๐Ÿฆœ๐Ÿฆ๐Ÿฆž๐ŸฆŸ๐Ÿฆ ๐Ÿฆก๐Ÿฆข๐Ÿฆฃ๐Ÿฆค๐Ÿฆฅ๐Ÿฆฆ๐Ÿฆง๐Ÿฆจ๐Ÿฆฉ๐Ÿฆช๐Ÿฆซ๐Ÿฆฌ๐Ÿฆญ๐Ÿฆฎ"
96
  # article = "<p style='text-align: center'></p>"
97
  examples=[
98
  ['Achilles-art-scale-6_00x-gigapixel.png', 'Simple Lines'],