ohaiyo123 commited on
Commit
5a742ab
·
verified ·
1 Parent(s): 1ce02a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -7,27 +7,27 @@ from deoldify import device
7
  from deoldify.device_id import DeviceId
8
  from deoldify.visualize import get_image_colorizer
9
 
10
- # Ẩn warning khó chịu của fastai
11
  warnings.filterwarnings("ignore", category=UserWarning, message=".*?Your .*? set is empty.*?")
12
 
13
- # ⚡ Thiết lập thiết bị
14
  try:
15
  device.set(device=DeviceId.GPU0)
16
  except Exception:
17
  device.set(device=DeviceId.CPU)
18
 
19
- # 🧠 Tải model từ Hugging Face Hub (dùng repo có sẵn model)
20
- REPO_ID = "leonelhs/deoldify" # 👈 bạn có thể thay repo này bằng repo model của bạn
21
  snapshot_folder = snapshot_download(repo_id=REPO_ID)
22
 
23
- # 🟡 Load DeOldify colorizer
24
  colorizer = get_image_colorizer(root_folder=Path(snapshot_folder), artistic=True)
25
 
26
- # 🧾 Hàm dự đoán
27
  def predict(image, render_factor=35):
28
  return colorizer.get_transformed_image(image, render_factor=render_factor, watermarked=False)
29
 
30
- # 🖥️ API/Gradio Interface
31
  demo = gr.Interface(
32
  fn=predict,
33
  inputs=[
@@ -35,8 +35,8 @@ demo = gr.Interface(
35
  gr.Slider(7, 40, value=35, step=1, label="Render Factor (Chất lượng)")
36
  ],
37
  outputs=gr.Image(type="pil", label="Ảnh sau khi tô màu"),
38
- title="🖼️ DeOldify API - AI Tô Màu Ảnh Trắng Đen",
39
- description="Upload ảnh trắng đen — mô hình sẽ tự động tô màu bằng DeOldify.",
40
  )
41
 
42
  if __name__ == "__main__":
 
7
  from deoldify.device_id import DeviceId
8
  from deoldify.visualize import get_image_colorizer
9
 
10
+
11
  warnings.filterwarnings("ignore", category=UserWarning, message=".*?Your .*? set is empty.*?")
12
 
13
+
14
  try:
15
  device.set(device=DeviceId.GPU0)
16
  except Exception:
17
  device.set(device=DeviceId.CPU)
18
 
19
+
20
+ REPO_ID = "leonelhs/deoldify"
21
  snapshot_folder = snapshot_download(repo_id=REPO_ID)
22
 
23
+
24
  colorizer = get_image_colorizer(root_folder=Path(snapshot_folder), artistic=True)
25
 
26
+
27
  def predict(image, render_factor=35):
28
  return colorizer.get_transformed_image(image, render_factor=render_factor, watermarked=False)
29
 
30
+
31
  demo = gr.Interface(
32
  fn=predict,
33
  inputs=[
 
35
  gr.Slider(7, 40, value=35, step=1, label="Render Factor (Chất lượng)")
36
  ],
37
  outputs=gr.Image(type="pil", label="Ảnh sau khi tô màu"),
38
+ title="Phục dựng ảnh lịch sử",
39
+ description="Upload ảnh lịch sử.",
40
  )
41
 
42
  if __name__ == "__main__":