rmayormartins commited on
Commit
91c5d6f
1 Parent(s): ece08bc

Atualização do README com créditos

Browse files
Files changed (2) hide show
  1. README.md +6 -0
  2. app.py +13 -13
README.md CHANGED
@@ -11,3 +11,9 @@ license: ecl-2.0
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
14
+
15
+ Desenvolvido por Ramon Mayor Martins (2023)
16
+ mail rmayormartins@gmail.com
17
+ hp https://rmayormartins.github.io/
18
+ twitter @rmayormartins
19
+ github https://github.com/rmayormartins
app.py CHANGED
@@ -4,16 +4,16 @@ import numpy as np
4
  import gradio as gr
5
  import cv2
6
 
7
- # Tamanho padrão para o redimensionamento das imagens
8
  IMAGE_SIZE = (256, 256)
9
 
10
- # Carrega o modelo de transferência de estilo pré-treinado
11
  style_transfer_model = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2')
12
 
13
  def load_image(image):
14
- # Redimensiona a imagem para o tamanho padrão
15
  image = cv2.resize(image, IMAGE_SIZE, interpolation=cv2.INTER_AREA)
16
- # Processa a imagem para o modelo
17
  image = image.astype(np.float32)[np.newaxis, ...] / 255.
18
  if image.shape[-1] == 4:
19
  image = image[..., :3]
@@ -27,40 +27,40 @@ def apply_sharpness(image, intensity):
27
  return np.clip(sharp_image, 0, 255)
28
 
29
  def interpolate_images(baseline, target, alpha):
30
- # Interpola entre duas imagens com um fator alpha
31
  return baseline + alpha * (target - baseline)
32
 
33
  def style_transfer(content_image, style_image, style_density, content_sharpness):
34
- # Processa as imagens
35
  content_image = load_image(content_image)
36
  style_image = load_image(style_image)
37
 
38
- # Aplica nitidez na imagem de conteúdo antes da transferência de estilo
39
  content_image_sharp = apply_sharpness(content_image[0], intensity=content_sharpness)
40
  content_image_sharp = content_image_sharp[np.newaxis, ...]
41
 
42
- # Executa a transferência de estilo
43
  stylized_image = style_transfer_model(tf.constant(content_image_sharp), tf.constant(style_image))[0]
44
 
45
- # Interpola entre a imagem de conteúdo e a imagem estilizada para densidade de estilo
46
  stylized_image = interpolate_images(
47
  baseline=content_image[0],
48
  target=stylized_image.numpy(),
49
  alpha=style_density
50
  )
51
 
52
- # Converte a imagem resultante para o formato correto
53
  stylized_image = np.array(stylized_image * 255, np.uint8)
54
 
55
- # Remove a dimensão do batch
56
  stylized_image = np.squeeze(stylized_image)
57
  return stylized_image
58
 
59
  iface = gr.Interface(
60
  fn=style_transfer,
61
  inputs=[
62
- gr.Image(label="Content Image"), # Imagem de conteúdo
63
- gr.Image(label="Style Image"), # Imagem de estilo
64
  gr.Slider(minimum=0, maximum=1, value=0.5, label="Adjust Style Density"),
65
  gr.Slider(minimum=0, maximum=1, value=0.5, label="Content Sharpness")
66
  ],
 
4
  import gradio as gr
5
  import cv2
6
 
7
+
8
  IMAGE_SIZE = (256, 256)
9
 
10
+
11
  style_transfer_model = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2')
12
 
13
  def load_image(image):
14
+
15
  image = cv2.resize(image, IMAGE_SIZE, interpolation=cv2.INTER_AREA)
16
+
17
  image = image.astype(np.float32)[np.newaxis, ...] / 255.
18
  if image.shape[-1] == 4:
19
  image = image[..., :3]
 
27
  return np.clip(sharp_image, 0, 255)
28
 
29
  def interpolate_images(baseline, target, alpha):
30
+
31
  return baseline + alpha * (target - baseline)
32
 
33
  def style_transfer(content_image, style_image, style_density, content_sharpness):
34
+ #
35
  content_image = load_image(content_image)
36
  style_image = load_image(style_image)
37
 
38
+
39
  content_image_sharp = apply_sharpness(content_image[0], intensity=content_sharpness)
40
  content_image_sharp = content_image_sharp[np.newaxis, ...]
41
 
42
+
43
  stylized_image = style_transfer_model(tf.constant(content_image_sharp), tf.constant(style_image))[0]
44
 
45
+
46
  stylized_image = interpolate_images(
47
  baseline=content_image[0],
48
  target=stylized_image.numpy(),
49
  alpha=style_density
50
  )
51
 
52
+
53
  stylized_image = np.array(stylized_image * 255, np.uint8)
54
 
55
+
56
  stylized_image = np.squeeze(stylized_image)
57
  return stylized_image
58
 
59
  iface = gr.Interface(
60
  fn=style_transfer,
61
  inputs=[
62
+ gr.Image(label="Content Image"),
63
+ gr.Image(label="Style Image"),
64
  gr.Slider(minimum=0, maximum=1, value=0.5, label="Adjust Style Density"),
65
  gr.Slider(minimum=0, maximum=1, value=0.5, label="Content Sharpness")
66
  ],