Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,37 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
from
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
colorized = colorization_pipeline(image)
|
| 14 |
-
return colorized
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
interface = gr.Interface(
|
| 18 |
fn=colorize_image,
|
| 19 |
-
inputs=gr.Image(type="
|
| 20 |
-
outputs=gr.Image(type="
|
| 21 |
title="Colorização de Imagens com IA",
|
| 22 |
-
description="
|
| 23 |
)
|
| 24 |
|
| 25 |
-
# Executar a aplicação
|
| 26 |
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import sys
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
import requests
|
| 5 |
+
from fastai.vision import *
|
| 6 |
+
from deoldify.visualize import *
|
| 7 |
|
| 8 |
+
# Baixar pesos do modelo
|
| 9 |
+
model_path = Path("./models/ColorizeArtistic_gen.pth")
|
| 10 |
+
if not model_path.exists():
|
| 11 |
+
model_path.parent.mkdir(parents=True, exist_ok=True)
|
| 12 |
+
url = "https://data.deepai.org/deoldify/ColorizeArtistic_gen.pth"
|
| 13 |
+
response = requests.get(url, stream=True)
|
| 14 |
+
with open(model_path, "wb") as f:
|
| 15 |
+
for chunk in response.iter_content(chunk_size=1024):
|
| 16 |
+
f.write(chunk)
|
| 17 |
|
| 18 |
+
# Configurar o modelo DeOldify
|
| 19 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 20 |
+
colorizer = get_stable_image_colorizer(root_folder=".", artistic=True)
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
def colorize_image(input_image):
|
| 23 |
+
output = colorizer.plot_transformed_image(
|
| 24 |
+
path=input_image, render_factor=35, display_render_factor=True, figsize=(20, 20)
|
| 25 |
+
)
|
| 26 |
+
return output
|
| 27 |
+
|
| 28 |
+
# Interface do Gradio
|
| 29 |
interface = gr.Interface(
|
| 30 |
fn=colorize_image,
|
| 31 |
+
inputs=gr.Image(type="filepath", label="Imagem em Preto e Branco"),
|
| 32 |
+
outputs=gr.Image(type="auto", label="Imagem Colorida"),
|
| 33 |
title="Colorização de Imagens com IA",
|
| 34 |
+
description="Carregue uma imagem em preto e branco, e o modelo colorizará automaticamente!",
|
| 35 |
)
|
| 36 |
|
|
|
|
| 37 |
interface.launch()
|