Spaces:
Running
Running
Upload 2 files
Browse files- app.py +56 -0
- requirements.txt +13 -0
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import warnings
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
import gradio as gr
|
| 6 |
+
from deoldify import device
|
| 7 |
+
from deoldify.device_id import DeviceId
|
| 8 |
+
from deoldify.visualize import get_image_colorizer
|
| 9 |
+
from huggingface_hub import snapshot_download
|
| 10 |
+
|
| 11 |
+
os.system("pip freeze")
|
| 12 |
+
warnings.filterwarnings("ignore", category=UserWarning, message=".*?Your .*? set is empty.*?")
|
| 13 |
+
|
| 14 |
+
device.set(device=DeviceId.CPU)
|
| 15 |
+
|
| 16 |
+
REPO_ID = "leonelhs/deoldify"
|
| 17 |
+
snapshot_folder = snapshot_download(repo_id=REPO_ID)
|
| 18 |
+
|
| 19 |
+
device.set(device=DeviceId.GPU0)
|
| 20 |
+
colorizer = get_image_colorizer(root_folder=Path(snapshot_folder), artistic=True)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def predict(image):
|
| 24 |
+
return colorizer.get_transformed_image(image, render_factor=35, watermarked=False)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
title = "DeOldify"
|
| 28 |
+
description = r"""
|
| 29 |
+
## Colorize image
|
| 30 |
+
|
| 31 |
+
This is an implementation of <a href='https://github.com/jantic/DeOldify' target='_blank'>DeOldify</a>.
|
| 32 |
+
It has no any particular purpose than start research on AI models.
|
| 33 |
+
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
article = r"""
|
| 37 |
+
Questions, doubts, comments, please email 📧 `[email protected]`
|
| 38 |
+
|
| 39 |
+
This demo is running on a CPU, if you like this project please make us a donation to run on a GPU or just give us a <a href='https://github.com/jantic/DeOldify' target='_blank'>Github ⭐</a>
|
| 40 |
+
|
| 41 |
+
<a href="https://www.buymeacoffee.com/leonelhs"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=&slug=leonelhs&button_colour=FFDD00&font_colour=000000&font_family=Cookie&outline_colour=000000&coffee_colour=ffffff" /></a>
|
| 42 |
+
|
| 43 |
+
<center><img src='https://visitor-badge.glitch.me/badge?page_id=deoldify.visitor-badge' alt='visitor badge'></center>
|
| 44 |
+
"""
|
| 45 |
+
|
| 46 |
+
demo = gr.Interface(
|
| 47 |
+
predict, [
|
| 48 |
+
gr.Image(type="filepath", label="Image gray scale"),
|
| 49 |
+
], [
|
| 50 |
+
gr.Image(type="pil", label="Image color")
|
| 51 |
+
],
|
| 52 |
+
title=title,
|
| 53 |
+
description=description,
|
| 54 |
+
article=article)
|
| 55 |
+
|
| 56 |
+
demo.queue().launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch~=2.5.1
|
| 2 |
+
torchvision~=0.20.1
|
| 3 |
+
numpy~=1.24.3
|
| 4 |
+
pillow~=9.5.0
|
| 5 |
+
opencv-python~=4.10.0.84
|
| 6 |
+
scipy~=1.13.1
|
| 7 |
+
fastprogress~=1.0.3
|
| 8 |
+
deoldify~=0.0.1
|
| 9 |
+
matplotlib~=3.9.3
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|