Hotcobra commited on
Commit
c60ebdc
·
verified ·
1 Parent(s): 2185d8e

Update requirements.txt

Browse files
Files changed (1) hide show
  1. requirements.txt +94 -10
requirements.txt CHANGED
@@ -1,10 +1,94 @@
1
- numpy
2
- Pillow
3
- torch==2.2.2+cpu
4
- torchvision==0.17.2+cpu
5
- --extra-index-url https://download.pytorch.org/whl/cpu
6
- scikit-image
7
- gradio[oauth,mcp]==6.18.0
8
- uvicorn>=0.14.0
9
- websockets>=10.4
10
- spaces
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from PIL import Image
4
+ from skimage import color as skcolor
5
+
6
+ # -----------------------------
7
+ # TEST MODE (subtle tint)
8
+ # -----------------------------
9
+ def test_mode_colorize(pil_img: Image.Image) -> Image.Image:
10
+ img = pil_img.convert("RGB")
11
+ arr = np.array(img).astype(np.float32) / 255.0
12
+ tint = np.array([1.02, 1.0, 0.98], dtype=np.float32)
13
+ arr = np.clip(arr * tint, 0.0, 1.0)
14
+ arr = (arr * 255).astype(np.uint8)
15
+ return Image.fromarray(arr)
16
+
17
+ # -----------------------------
18
+ # DEOLDIFY‑LITE (CPU SAFE)
19
+ # -----------------------------
20
+ def deoldify_lite_colorize(pil_img: Image.Image) -> Image.Image:
21
+ img = pil_img.convert("RGB")
22
+ arr = np.array(img).astype(np.float32) / 255.0
23
+
24
+ lab = skcolor.rgb2lab(arr)
25
+ L = lab[:, :, 0]
26
+ a = lab[:, :, 1]
27
+ b = lab[:, :, 2]
28
+
29
+ a *= 1.35
30
+ b *= 1.35
31
+ a += 2.0
32
+ b += 1.0
33
+
34
+ lab_out = np.stack([L, a, b], axis=-1)
35
+ rgb_out = skcolor.lab2rgb(lab_out)
36
+ rgb_out = np.clip(rgb_out, 0.0, 1.0)
37
+ rgb_out = (rgb_out * 255).astype(np.uint8)
38
+
39
+ return Image.fromarray(rgb_out)
40
+
41
+ # -----------------------------
42
+ # MAIN PIPELINE
43
+ # -----------------------------
44
+ def colorize_image(input_image, mode):
45
+ if input_image is None:
46
+ return None
47
+
48
+ pil_img = input_image.convert("RGB")
49
+
50
+ if mode == "Test Mode (Very Subtle)":
51
+ return test_mode_colorize(pil_img)
52
+
53
+ if mode == "DeOldify‑Lite (Art Mode)":
54
+ return deoldify_lite_colorize(pil_img)
55
+
56
+ return test_mode_colorize(pil_img)
57
+
58
+ # -----------------------------
59
+ # GRADIO UI
60
+ # -----------------------------
61
+ with gr.Blocks(title="Biker Image Colorizer – CPU (Test + DeOldify‑Lite)") as demo:
62
+ gr.Markdown(
63
+ """
64
+ # Biker Image Colorizer – CPU Edition
65
+ **Two modes:**
66
+ - Test Mode (very subtle)
67
+ - DeOldify‑Lite (artistic strong color)
68
+ """
69
+ )
70
+
71
+ with gr.Row():
72
+ with gr.Column():
73
+ input_image = gr.Image(type="pil", label="Input Image")
74
+ mode = gr.Radio(
75
+ choices=[
76
+ "Test Mode (Very Subtle)",
77
+ "DeOldify‑Lite (Art Mode)",
78
+ ],
79
+ value="DeOldify‑Lite (Art Mode)",
80
+ label="Colorization Mode",
81
+ )
82
+ run_btn = gr.Button("Colorize", variant="primary")
83
+
84
+ with gr.Column():
85
+ output_image = gr.Image(type="pil", label="Output Image")
86
+
87
+ run_btn.click(
88
+ fn=colorize_image,
89
+ inputs=[input_image, mode],
90
+ outputs=[output_image],
91
+ )
92
+
93
+ if __name__ == "__main__":
94
+ demo.launch()