breynolds1247 commited on
Commit
40943a1
1 Parent(s): aab9871

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -4
app.py CHANGED
@@ -12,8 +12,67 @@ from PIL import Image
12
  import gradio as gr
13
  import os
14
 
15
- #Load Magenta Arbitrary Image Stylization network
16
- hub_module = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/1')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  """
18
  def inference(input_image):
19
  preprocess = transforms.Compose([
@@ -63,14 +122,14 @@ def inference(input_image):
63
  ##title = "Artist Classifier"
64
  ##description = "Gradio demo for MOBILENET V2, Efficient networks optimized for speed and memory, with residual blocks. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
65
  ##article = "<p style='text-align: center'><a href='https://arxiv.org/abs/1801.04381'>MobileNetV2: Inverted Residuals and Linear Bottlenecks</a> | <a href='https://github.com/pytorch/vision/blob/master/torchvision/models/mobilenet.py'>Github Repo</a></p>"
66
-
67
  def greet(name):
68
  return "Hello " + name + "!!"
69
 
70
  demo = gr.Interface(fn=greet, inputs="text", outputs="text")
71
 
72
  demo.launch()
73
-
74
  #examples = [
75
  # ['dog.jpg']
76
  #]
 
12
  import gradio as gr
13
  import os
14
 
15
+ from helper_functions import *
16
+
17
+ def style_transfer(input_image, artist):
18
+
19
+ style_path_van_gogh = keras.utils.get_file('Starry-Night-canvas-Vincent-van-Gogh-New-1889.jpg',
20
+ 'https://cdn.britannica.com/78/43678-050-F4DC8D93/Starry-Night-canvas-Vincent-van-Gogh-New-1889.jpg')
21
+ style_path_davinci = keras.utils.get_file('Leonardo_da_Vinci_-_Mona_Lisa_%28La_Gioconda%29_-_WGA12711.jpg',
22
+ 'https://upload.wikimedia.org/wikipedia/commons/f/f2/Leonardo_da_Vinci_-_Mona_Lisa_%28La_Gioconda%29_-_WGA12711.jpg')
23
+ style_path_dali = keras.utils.get_file('The_Persistence_of_Memory.jpg',
24
+ 'https://upload.wikimedia.org/wikipedia/en/d/dd/The_Persistence_of_Memory.jpg')
25
+ style_path_monet = keras.utils.get_file('Claude_Monet_-_Water_Lilies_-_Google_Art_Project_%28462013%29.jpg',
26
+ 'https://upload.wikimedia.org/wikipedia/commons/a/af/Claude_Monet_-_Water_Lilies_-_Google_Art_Project_%28462013%29.jpg')
27
+ style_path_picasso = keras.utils.get_file('Picasso_The_Weeping_Woman_Tate_identifier_T05010_10.jpg',
28
+ 'https://upload.wikimedia.org/wikipedia/en/1/14/Picasso_The_Weeping_Woman_Tate_identifier_T05010_10.jpg')
29
+ style_path_rembrandt = keras.utils.get_file('1259px-The_Nightwatch_by_Rembrandt_-_Rijksmuseum.jpg',
30
+ 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/94/The_Nightwatch_by_Rembrandt_-_Rijksmuseum.jpg/1259px-The_Nightwatch_by_Rembrandt_-_Rijksmuseum.jpg')
31
+
32
+ #set dimensions of input image
33
+ oc_max_dim = 1080
34
+
35
+ #set parameters for each choice of artist
36
+ if artist == "Vincent van Gogh":
37
+ style_max_dim = 442
38
+ style_path = style_path_van_gogh
39
+ elif artist == "Claude Monet":
40
+ style_max_dim = 256
41
+ style_path = style_path_monet
42
+ elif artist == "Leonardo da Vinci":
43
+ style_max_dim = 442
44
+ style_path = style_path_davinci
45
+ elif artist == "Rembrandt":
46
+ style_max_dim = 256
47
+ style_path = style_path_rembrandt
48
+ elif artist == "Pablo Picasso":
49
+ style_max_dim = 256
50
+ style_path = style_path_picasso
51
+ elif artist == "Salvador Dali":
52
+ style_max_dim = 512
53
+ style_path = style_path_dali
54
+
55
+ #load content and style images
56
+ content_image = load_img(input_image, max_dim=oc_max_dim)
57
+ style_image = load_img(style_path, style_max_dim)
58
+
59
+ #Load Magenta Arbitrary Image Stylization network
60
+ hub_module = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/1')
61
+
62
+ #Pass content and style images as arguments in TensorFlow Constant object format
63
+ stylized_image = hub_module(tf.constant(content_image), tf.constant(style_image))[0]
64
+
65
+ return stylized_image
66
+
67
+ app = gr.Interface(
68
+ style_transfer,
69
+ [gr.Image(type='pil'), gr.Radio(["Vincent van Gogh", "Claude Monet", "Leonardo da Vinci", "Rembrandt", "Pablo Picasso", "Salvador Dali"])],
70
+ gr.Image(type='pil'),
71
+ title="Artist Style Transfer Tool",
72
+ description="Make your own art in the style of six famous artists using pretrained neural networks and deep learning!"
73
+ #article="https://arxiv.org/abs/1705.06830"
74
+ )
75
+
76
  """
77
  def inference(input_image):
78
  preprocess = transforms.Compose([
 
122
  ##title = "Artist Classifier"
123
  ##description = "Gradio demo for MOBILENET V2, Efficient networks optimized for speed and memory, with residual blocks. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
124
  ##article = "<p style='text-align: center'><a href='https://arxiv.org/abs/1801.04381'>MobileNetV2: Inverted Residuals and Linear Bottlenecks</a> | <a href='https://github.com/pytorch/vision/blob/master/torchvision/models/mobilenet.py'>Github Repo</a></p>"
125
+ """
126
  def greet(name):
127
  return "Hello " + name + "!!"
128
 
129
  demo = gr.Interface(fn=greet, inputs="text", outputs="text")
130
 
131
  demo.launch()
132
+ """
133
  #examples = [
134
  # ['dog.jpg']
135
  #]