Update app.py
Browse files
app.py
CHANGED
|
@@ -2,9 +2,27 @@ import numpy as np
|
|
| 2 |
import torch
|
| 3 |
import torch.nn as nn
|
| 4 |
import gradio as gr
|
| 5 |
-
from PIL import Image
|
| 6 |
import torchvision.transforms as transforms
|
| 7 |
-
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# 🧠 Neural network layers
|
| 10 |
norm_layer = nn.InstanceNorm2d
|
|
@@ -13,16 +31,13 @@ norm_layer = nn.InstanceNorm2d
|
|
| 13 |
class ResidualBlock(nn.Module):
|
| 14 |
def __init__(self, in_features):
|
| 15 |
super(ResidualBlock, self).__init__()
|
| 16 |
-
|
| 17 |
conv_block = [ nn.ReflectionPad2d(1),
|
| 18 |
nn.Conv2d(in_features, in_features, 3),
|
| 19 |
norm_layer(in_features),
|
| 20 |
nn.ReLU(inplace=True),
|
| 21 |
nn.ReflectionPad2d(1),
|
| 22 |
nn.Conv2d(in_features, in_features, 3),
|
| 23 |
-
norm_layer(in_features)
|
| 24 |
-
]
|
| 25 |
-
|
| 26 |
self.conv_block = nn.Sequential(*conv_block)
|
| 27 |
|
| 28 |
def forward(self, x):
|
|
@@ -32,15 +47,13 @@ class ResidualBlock(nn.Module):
|
|
| 32 |
class Generator(nn.Module):
|
| 33 |
def __init__(self, input_nc, output_nc, n_residual_blocks=9, sigmoid=True):
|
| 34 |
super(Generator, self).__init__()
|
| 35 |
-
|
| 36 |
-
# 🏁 Initial convolution block
|
| 37 |
model0 = [ nn.ReflectionPad2d(3),
|
| 38 |
nn.Conv2d(input_nc, 64, 7),
|
| 39 |
norm_layer(64),
|
| 40 |
nn.ReLU(inplace=True) ]
|
| 41 |
self.model0 = nn.Sequential(*model0)
|
| 42 |
-
|
| 43 |
-
# 🔽 Downsampling
|
| 44 |
model1 = []
|
| 45 |
in_features = 64
|
| 46 |
out_features = in_features*2
|
|
@@ -51,14 +64,12 @@ class Generator(nn.Module):
|
|
| 51 |
in_features = out_features
|
| 52 |
out_features = in_features*2
|
| 53 |
self.model1 = nn.Sequential(*model1)
|
| 54 |
-
|
| 55 |
-
# 🔁 Residual blocks
|
| 56 |
model2 = []
|
| 57 |
for _ in range(n_residual_blocks):
|
| 58 |
model2 += [ResidualBlock(in_features)]
|
| 59 |
self.model2 = nn.Sequential(*model2)
|
| 60 |
-
|
| 61 |
-
# 🔼 Upsampling
|
| 62 |
model3 = []
|
| 63 |
out_features = in_features//2
|
| 64 |
for _ in range(2):
|
|
@@ -68,13 +79,11 @@ class Generator(nn.Module):
|
|
| 68 |
in_features = out_features
|
| 69 |
out_features = in_features//2
|
| 70 |
self.model3 = nn.Sequential(*model3)
|
| 71 |
-
|
| 72 |
-
# 🎭 Output layer
|
| 73 |
model4 = [ nn.ReflectionPad2d(3),
|
| 74 |
-
|
| 75 |
if sigmoid:
|
| 76 |
model4 += [nn.Sigmoid()]
|
| 77 |
-
|
| 78 |
self.model4 = nn.Sequential(*model4)
|
| 79 |
|
| 80 |
def forward(self, x, cond=None):
|
|
@@ -83,71 +92,161 @@ class Generator(nn.Module):
|
|
| 83 |
out = self.model2(out)
|
| 84 |
out = self.model3(out)
|
| 85 |
out = self.model4(out)
|
| 86 |
-
|
| 87 |
return out
|
| 88 |
|
| 89 |
# 🔧 Load the models
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
model1
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
model2
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
original_size = original_img.size
|
| 103 |
|
| 104 |
-
# Define the transformation pipeline
|
| 105 |
transform = transforms.Compose([
|
| 106 |
-
transforms.Resize(256,
|
| 107 |
transforms.ToTensor(),
|
| 108 |
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
|
| 109 |
])
|
|
|
|
| 110 |
|
| 111 |
-
# Apply the transformation
|
| 112 |
-
input_tensor = transform(original_img)
|
| 113 |
-
input_tensor = input_tensor.unsqueeze(0)
|
| 114 |
-
|
| 115 |
-
# Process the image through the model
|
| 116 |
with torch.no_grad():
|
| 117 |
-
if
|
| 118 |
output = model2(input_tensor)
|
| 119 |
-
else:
|
| 120 |
output = model1(input_tensor)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
-
#
|
| 123 |
-
|
| 124 |
|
| 125 |
-
|
| 126 |
-
output_img = output_img.resize(original_size, Image.BICUBIC)
|
| 127 |
|
| 128 |
-
|
|
|
|
|
|
|
| 129 |
|
| 130 |
-
#
|
| 131 |
-
|
| 132 |
|
| 133 |
-
#
|
| 134 |
examples = []
|
| 135 |
-
image_dir = '.'
|
| 136 |
-
|
| 137 |
-
if
|
| 138 |
-
|
| 139 |
-
examples
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
-
# 🚀 Create and launch the Gradio interface
|
| 142 |
iface = gr.Interface(
|
| 143 |
-
fn=predict,
|
| 144 |
inputs=[
|
| 145 |
-
gr.Image(type='filepath'),
|
| 146 |
-
gr.Radio(['Complex Lines', 'Simple Lines'], label='
|
|
|
|
| 147 |
],
|
| 148 |
-
outputs=gr.Image(type="pil"),
|
| 149 |
title=title,
|
| 150 |
-
|
|
|
|
|
|
|
| 151 |
)
|
| 152 |
|
| 153 |
-
|
|
|
|
|
|
| 2 |
import torch
|
| 3 |
import torch.nn as nn
|
| 4 |
import gradio as gr
|
| 5 |
+
from PIL import Image, ImageFilter, ImageOps, ImageChops
|
| 6 |
import torchvision.transforms as transforms
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
# 🎨 Dictionary of all filters with their corresponding emojis
|
| 10 |
+
FILTERS = {
|
| 11 |
+
"Standard": "📄", "Invert": "⚫⚪", "Blur": "🌫️", "Sharpen": "🔪", "Contour": "🗺️",
|
| 12 |
+
"Detail": "🔍", "EdgeEnhance": "📏", "EdgeEnhanceMore": "📐", "Emboss": "🏞️",
|
| 13 |
+
"FindEdges": "🕵️", "Smooth": "🌊", "SmoothMore": "💧", "Solarize": "☀️",
|
| 14 |
+
"Posterize1": "🖼️1", "Posterize2": "🖼️2", "Posterize3": "🖼️3", "Posterize4": "🖼️4",
|
| 15 |
+
"Equalize": "⚖️", "AutoContrast": "🔧", "Thick1": "💪1", "Thick2": "💪2", "Thick3": "💪3",
|
| 16 |
+
"Thin1": "🏃1", "Thin2": "🏃2", "Thin3": "🏃3", "RedOnWhite": "🔴", "OrangeOnWhite": "🟠",
|
| 17 |
+
"YellowOnWhite": "🟡", "GreenOnWhite": "🟢", "BlueOnWhite": "🔵", "PurpleOnWhite": "🟣",
|
| 18 |
+
"PinkOnWhite": "🌸", "CyanOnWhite": "🩵", "MagentaOnWhite": "🟪", "BrownOnWhite": "🤎",
|
| 19 |
+
"GrayOnWhite": "🩶", "WhiteOnBlack": "⚪", "RedOnBlack": "🔴⚫", "OrangeOnBlack": "🟠⚫",
|
| 20 |
+
"YellowOnBlack": "🟡⚫", "GreenOnBlack": "🟢⚫", "BlueOnBlack": "🔵⚫", "PurpleOnBlack": "🟣⚫",
|
| 21 |
+
"PinkOnBlack": "🌸⚫", "CyanOnBlack": "🩵⚫", "MagentaOnBlack": "🟪⚫", "BrownOnBlack": "🤎⚫",
|
| 22 |
+
"GrayOnBlack": "🩶⚫", "Multiply": "✖️", "Screen": "🖥️", "Overlay": "🔲", "Add": "➕",
|
| 23 |
+
"Subtract": "➖", "Difference": "≠", "Darker": "🌑", "Lighter": "🌕", "SoftLight": "💡",
|
| 24 |
+
"HardLight": "🔦", "Binary": "🌓", "Noise": "❄️"
|
| 25 |
+
}
|
| 26 |
|
| 27 |
# 🧠 Neural network layers
|
| 28 |
norm_layer = nn.InstanceNorm2d
|
|
|
|
| 31 |
class ResidualBlock(nn.Module):
|
| 32 |
def __init__(self, in_features):
|
| 33 |
super(ResidualBlock, self).__init__()
|
|
|
|
| 34 |
conv_block = [ nn.ReflectionPad2d(1),
|
| 35 |
nn.Conv2d(in_features, in_features, 3),
|
| 36 |
norm_layer(in_features),
|
| 37 |
nn.ReLU(inplace=True),
|
| 38 |
nn.ReflectionPad2d(1),
|
| 39 |
nn.Conv2d(in_features, in_features, 3),
|
| 40 |
+
norm_layer(in_features) ]
|
|
|
|
|
|
|
| 41 |
self.conv_block = nn.Sequential(*conv_block)
|
| 42 |
|
| 43 |
def forward(self, x):
|
|
|
|
| 47 |
class Generator(nn.Module):
|
| 48 |
def __init__(self, input_nc, output_nc, n_residual_blocks=9, sigmoid=True):
|
| 49 |
super(Generator, self).__init__()
|
| 50 |
+
# Initial convolution block
|
|
|
|
| 51 |
model0 = [ nn.ReflectionPad2d(3),
|
| 52 |
nn.Conv2d(input_nc, 64, 7),
|
| 53 |
norm_layer(64),
|
| 54 |
nn.ReLU(inplace=True) ]
|
| 55 |
self.model0 = nn.Sequential(*model0)
|
| 56 |
+
# Downsampling
|
|
|
|
| 57 |
model1 = []
|
| 58 |
in_features = 64
|
| 59 |
out_features = in_features*2
|
|
|
|
| 64 |
in_features = out_features
|
| 65 |
out_features = in_features*2
|
| 66 |
self.model1 = nn.Sequential(*model1)
|
| 67 |
+
# Residual blocks
|
|
|
|
| 68 |
model2 = []
|
| 69 |
for _ in range(n_residual_blocks):
|
| 70 |
model2 += [ResidualBlock(in_features)]
|
| 71 |
self.model2 = nn.Sequential(*model2)
|
| 72 |
+
# Upsampling
|
|
|
|
| 73 |
model3 = []
|
| 74 |
out_features = in_features//2
|
| 75 |
for _ in range(2):
|
|
|
|
| 79 |
in_features = out_features
|
| 80 |
out_features = in_features//2
|
| 81 |
self.model3 = nn.Sequential(*model3)
|
| 82 |
+
# Output layer
|
|
|
|
| 83 |
model4 = [ nn.ReflectionPad2d(3),
|
| 84 |
+
nn.Conv2d(64, output_nc, 7)]
|
| 85 |
if sigmoid:
|
| 86 |
model4 += [nn.Sigmoid()]
|
|
|
|
| 87 |
self.model4 = nn.Sequential(*model4)
|
| 88 |
|
| 89 |
def forward(self, x, cond=None):
|
|
|
|
| 92 |
out = self.model2(out)
|
| 93 |
out = self.model3(out)
|
| 94 |
out = self.model4(out)
|
|
|
|
| 95 |
return out
|
| 96 |
|
| 97 |
# 🔧 Load the models
|
| 98 |
+
# Make sure you have 'model.pth' and 'model2.pth' in the same directory
|
| 99 |
+
try:
|
| 100 |
+
model1 = Generator(3, 1, 3)
|
| 101 |
+
model1.load_state_dict(torch.load('model.pth', map_location=torch.device('cpu')))
|
| 102 |
+
model1.eval()
|
| 103 |
+
|
| 104 |
+
model2 = Generator(3, 1, 3)
|
| 105 |
+
model2.load_state_dict(torch.load('model2.pth', map_location=torch.device('cpu')))
|
| 106 |
+
model2.eval()
|
| 107 |
+
except FileNotFoundError:
|
| 108 |
+
print("Warning: Model files 'model.pth' or 'model2.pth' not found. The application will not run correctly.")
|
| 109 |
+
model1, model2 = None, None
|
| 110 |
+
|
| 111 |
+
# ✨ Function to apply the selected filter
|
| 112 |
+
def apply_filter(line_img, filter_name, original_img):
|
| 113 |
+
if filter_name == "Standard":
|
| 114 |
+
return line_img
|
| 115 |
+
|
| 116 |
+
# Convert line drawing to grayscale for most operations
|
| 117 |
+
line_img_l = line_img.convert('L')
|
| 118 |
+
|
| 119 |
+
# --- Standard Image Filters ---
|
| 120 |
+
if filter_name == "Invert": return ImageOps.invert(line_img_l)
|
| 121 |
+
if filter_name == "Blur": return line_img.filter(ImageFilter.GaussianBlur(radius=3))
|
| 122 |
+
if filter_name == "Sharpen": return line_img.filter(ImageFilter.SHARPEN)
|
| 123 |
+
if filter_name == "Contour": return line_img_l.filter(ImageFilter.CONTOUR)
|
| 124 |
+
if filter_name == "Detail": return line_img.filter(ImageFilter.DETAIL)
|
| 125 |
+
if filter_name == "EdgeEnhance": return line_img_l.filter(ImageFilter.EDGE_ENHANCE)
|
| 126 |
+
if filter_name == "EdgeEnhanceMore": return line_img_l.filter(ImageFilter.EDGE_ENHANCE_MORE)
|
| 127 |
+
if filter_name == "Emboss": return line_img_l.filter(ImageFilter.EMBOSS)
|
| 128 |
+
if filter_name == "FindEdges": return line_img_l.filter(ImageFilter.FIND_EDGES)
|
| 129 |
+
if filter_name == "Smooth": return line_img.filter(ImageFilter.SMOOTH)
|
| 130 |
+
if filter_name == "SmoothMore": return line_img.filter(ImageFilter.SMOOTH_MORE)
|
| 131 |
+
|
| 132 |
+
# --- Tonal Adjustments ---
|
| 133 |
+
if filter_name == "Solarize": return ImageOps.solarize(line_img_l)
|
| 134 |
+
if filter_name == "Posterize1": return ImageOps.posterize(line_img_l, 1)
|
| 135 |
+
if filter_name == "Posterize2": return ImageOps.posterize(line_img_l, 2)
|
| 136 |
+
if filter_name == "Posterize3": return ImageOps.posterize(line_img_l, 3)
|
| 137 |
+
if filter_name == "Posterize4": return ImageOps.posterize(line_img_l, 4)
|
| 138 |
+
if filter_name == "Equalize": return ImageOps.equalize(line_img_l)
|
| 139 |
+
if filter_name == "AutoContrast": return ImageOps.autocontrast(line_img_l)
|
| 140 |
+
if filter_name == "Binary": return line_img_l.convert('1')
|
| 141 |
+
|
| 142 |
+
# --- Morphological Operations (Thick/Thin) ---
|
| 143 |
+
if filter_name == "Thick1": return line_img_l.filter(ImageFilter.MinFilter(3))
|
| 144 |
+
if filter_name == "Thick2": return line_img_l.filter(ImageFilter.MinFilter(5))
|
| 145 |
+
if filter_name == "Thick3": return line_img_l.filter(ImageFilter.MinFilter(7))
|
| 146 |
+
if filter_name == "Thin1": return line_img_l.filter(ImageFilter.MaxFilter(3))
|
| 147 |
+
if filter_name == "Thin2": return line_img_l.filter(ImageFilter.MaxFilter(5))
|
| 148 |
+
if filter_name == "Thin3": return line_img_l.filter(ImageFilter.MaxFilter(7))
|
| 149 |
+
|
| 150 |
+
# --- Colorization (On White Background) ---
|
| 151 |
+
colors_on_white = {"RedOnWhite": "red", "OrangeOnWhite": "orange", "YellowOnWhite": "yellow", "GreenOnWhite": "green", "BlueOnWhite": "blue", "PurpleOnWhite": "purple", "PinkOnWhite": "pink", "CyanOnWhite": "cyan", "MagentaOnWhite": "magenta", "BrownOnWhite": "brown", "GrayOnWhite": "gray"}
|
| 152 |
+
if filter_name in colors_on_white:
|
| 153 |
+
return ImageOps.colorize(line_img_l, black=colors_on_white[filter_name], white="white")
|
| 154 |
+
|
| 155 |
+
# --- Colorization (On Black Background) ---
|
| 156 |
+
colors_on_black = {"WhiteOnBlack": "white", "RedOnBlack": "red", "OrangeOnBlack": "orange", "YellowOnBlack": "yellow", "GreenOnBlack": "green", "BlueOnBlack": "blue", "PurpleOnBlack": "purple", "PinkOnBlack": "pink", "CyanOnBlack": "cyan", "MagentaOnBlack": "magenta", "BrownOnBlack": "brown", "GrayOnBlack": "gray"}
|
| 157 |
+
if filter_name in colors_on_black:
|
| 158 |
+
return ImageOps.colorize(line_img_l, black=colors_on_black[filter_name], white="black")
|
| 159 |
+
|
| 160 |
+
# --- Blending Modes with Original Image ---
|
| 161 |
+
line_img_rgb = line_img.convert('RGB')
|
| 162 |
+
if filter_name == "Multiply": return ImageChops.multiply(original_img, line_img_rgb)
|
| 163 |
+
if filter_name == "Screen": return ImageChops.screen(original_img, line_img_rgb)
|
| 164 |
+
if filter_name == "Overlay": return ImageChops.overlay(original_img, line_img_rgb)
|
| 165 |
+
if filter_name == "Add": return ImageChops.add(original_img, line_img_rgb)
|
| 166 |
+
if filter_name == "Subtract": return ImageChops.subtract(original_img, line_img_rgb)
|
| 167 |
+
if filter_name == "Difference": return ImageChops.difference(original_img, line_img_rgb)
|
| 168 |
+
if filter_name == "Darker": return ImageChops.darker(original_img, line_img_rgb)
|
| 169 |
+
if filter_name == "Lighter": return ImageChops.lighter(original_img, line_img_rgb)
|
| 170 |
+
if filter_name == "SoftLight": return ImageChops.soft_light(original_img, line_img_rgb)
|
| 171 |
+
if filter_name == "HardLight": return ImageChops.hard_light(original_img, line_img_rgb)
|
| 172 |
+
|
| 173 |
+
# --- Texture ---
|
| 174 |
+
if filter_name == "Noise":
|
| 175 |
+
img_array = np.array(line_img_l.convert('L'))
|
| 176 |
+
noise = np.random.randint(-20, 20, img_array.shape, dtype='int16')
|
| 177 |
+
noisy_array = np.clip(img_array.astype('int16') + noise, 0, 255).astype('uint8')
|
| 178 |
+
return Image.fromarray(noisy_array)
|
| 179 |
+
|
| 180 |
+
return line_img # Default fallback
|
| 181 |
+
|
| 182 |
+
# 🖼️ Main function to process the image
|
| 183 |
+
def predict(input_img_path, line_style, filter_choice):
|
| 184 |
+
if not model1 or not model2:
|
| 185 |
+
raise gr.Error("Models are not loaded. Please check for 'model.pth' and 'model2.pth'.")
|
| 186 |
+
|
| 187 |
+
# Extract the filter name from the dropdown choice (e.g., "📄 Standard" -> "Standard")
|
| 188 |
+
filter_name = filter_choice.split(" ", 1)[1]
|
| 189 |
+
|
| 190 |
+
original_img = Image.open(input_img_path).convert('RGB')
|
| 191 |
original_size = original_img.size
|
| 192 |
|
|
|
|
| 193 |
transform = transforms.Compose([
|
| 194 |
+
transforms.Resize(256, transforms.InterpolationMode.BICUBIC),
|
| 195 |
transforms.ToTensor(),
|
| 196 |
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
|
| 197 |
])
|
| 198 |
+
input_tensor = transform(original_img).unsqueeze(0)
|
| 199 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
with torch.no_grad():
|
| 201 |
+
if line_style == 'Simple Lines':
|
| 202 |
output = model2(input_tensor)
|
| 203 |
+
else: # Complex Lines
|
| 204 |
output = model1(input_tensor)
|
| 205 |
+
|
| 206 |
+
# Convert tensor to low-res PIL image
|
| 207 |
+
line_drawing_low_res = transforms.ToPILImage()(output.squeeze().cpu().clamp(0, 1))
|
| 208 |
+
|
| 209 |
+
# Resize the line drawing back to the original image size *before* applying filters
|
| 210 |
+
line_drawing_full_res = line_drawing_low_res.resize(original_size, Image.Resampling.BICUBIC)
|
| 211 |
|
| 212 |
+
# Apply the selected filter
|
| 213 |
+
final_image = apply_filter(line_drawing_full_res, filter_name, original_img)
|
| 214 |
|
| 215 |
+
return final_image
|
|
|
|
| 216 |
|
| 217 |
+
# 🚀 Setup and launch the Gradio interface
|
| 218 |
+
title = "🖌️ Image to Line Art with Creative Filters"
|
| 219 |
+
description = "Upload an image, choose a line style (Complex or Simple), and select a filter from the dropdown to transform your picture into unique line art."
|
| 220 |
|
| 221 |
+
# Generate dropdown choices with emojis
|
| 222 |
+
filter_choices = [f"{emoji} {name}" for name, emoji in FILTERS.items()]
|
| 223 |
|
| 224 |
+
# Dynamically generate examples from images in the current directory
|
| 225 |
examples = []
|
| 226 |
+
image_dir = '.'
|
| 227 |
+
if os.path.exists(image_dir):
|
| 228 |
+
image_files = [f for f in os.listdir(image_dir) if f.lower().endswith(('.png', '.jpg', '.jpeg'))]
|
| 229 |
+
if image_files:
|
| 230 |
+
# Pick the first image found and create examples with a few interesting filters
|
| 231 |
+
example_image = image_files[0]
|
| 232 |
+
examples.append([example_image, 'Simple Lines', '🗺️ Contour'])
|
| 233 |
+
examples.append([example_image, 'Complex Lines', '🔵⚫ BlueOnBlack'])
|
| 234 |
+
examples.append([example_image, 'Simple Lines', '✖️ Multiply'])
|
| 235 |
+
|
| 236 |
|
|
|
|
| 237 |
iface = gr.Interface(
|
| 238 |
+
fn=predict,
|
| 239 |
inputs=[
|
| 240 |
+
gr.Image(type='filepath', label="Upload Image"),
|
| 241 |
+
gr.Radio(['Complex Lines', 'Simple Lines'], label='Line Style', value='Simple Lines'),
|
| 242 |
+
gr.Dropdown(filter_choices, label="Filter", value=filter_choices[0])
|
| 243 |
],
|
| 244 |
+
outputs=gr.Image(type="pil", label="Filtered Line Art"),
|
| 245 |
title=title,
|
| 246 |
+
description=description,
|
| 247 |
+
examples=examples,
|
| 248 |
+
allow_flagging='never'
|
| 249 |
)
|
| 250 |
|
| 251 |
+
if __name__ == "__main__":
|
| 252 |
+
iface.launch()
|