rmayormartins commited on
Commit
eab0c71
1 Parent(s): 2f3f1a3

Add application file

Browse files
Files changed (1) hide show
  1. app.py +33 -3
app.py CHANGED
@@ -1,7 +1,37 @@
 
 
 
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()
 
1
+ import tensorflow as tf
2
+ import tensorflow_hub as hub
3
+ import numpy as np
4
  import gradio as gr
5
 
6
+ # Carrega o modelo de transferência de estilo pré-treinado
7
+ style_transfer_model = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2')
8
+
9
+ def load_image(image):
10
+ # Função para processar a imagem para o modelo
11
+ image = image.astype(np.float32)[np.newaxis, ...] / 255.
12
+ if image.shape[-1] == 4:
13
+ image = image[..., :3]
14
+ return image
15
+
16
+ def style_transfer(content_image, style_image):
17
+ # Processa as imagens
18
+ content_image = load_image(content_image)
19
+ style_image = load_image(style_image)
20
+
21
+ # Executa a transferência de estilo
22
+ stylized_image = style_transfer_model(tf.constant(content_image), tf.constant(style_image))[0]
23
+
24
+ # Converte a imagem resultante para o formato correto
25
+ stylized_image = np.array(stylized_image * 255, np.uint8)
26
+
27
+ # Remove a dimensão do batch
28
+ stylized_image = np.squeeze(stylized_image)
29
+ return stylized_image
30
+
31
+ iface = gr.Interface(
32
+ fn=style_transfer,
33
+ inputs=["image", "image"],
34
+ outputs="image"
35
+ )
36
 
 
37
  iface.launch()