Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,9 +4,8 @@
|
|
| 4 |
# 输出图片
|
| 5 |
# 使用 depth-anything + teed 生成外轮廓
|
| 6 |
# 使用 teed + 腐蚀算法 生成内边缘
|
| 7 |
-
|
| 8 |
-
|
| 9 |
from PIL import Image
|
|
|
|
| 10 |
import cv2
|
| 11 |
import numpy as np
|
| 12 |
import os
|
|
@@ -16,16 +15,11 @@ from torchvision.transforms import Compose
|
|
| 16 |
from tqdm import tqdm
|
| 17 |
import TEED.main as teed
|
| 18 |
from TEED.main import parse_args
|
| 19 |
-
import gradio as gr
|
| 20 |
-
|
| 21 |
|
| 22 |
from depthAnything.depth_anything.dpt import DepthAnything
|
| 23 |
from depthAnything.depth_anything.util.transform import Resize, NormalizeImage, PrepareForNet
|
| 24 |
import shutil
|
| 25 |
|
| 26 |
-
import sys
|
| 27 |
-
print(sys.path)
|
| 28 |
-
|
| 29 |
|
| 30 |
def multiply_blend(image1, image2):
|
| 31 |
# 将图片转换为浮点数,方便计算
|
|
@@ -358,28 +352,38 @@ def process_line(img_path='./input', outdir='./output'):
|
|
| 358 |
|
| 359 |
|
| 360 |
if __name__ == '__main__':
|
| 361 |
-
#
|
| 362 |
-
#
|
| 363 |
-
#
|
| 364 |
-
#
|
| 365 |
|
| 366 |
-
#
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
# erosion_img_from_path('./output/erosion_merged_imgs', './output/erosion2_merged_imgs', 2, 1, True)
|
| 370 |
-
img_path = "input"
|
| 371 |
-
outdir = "output"
|
| 372 |
-
process_line(img_path,outdir)
|
| 373 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
# 输出图片
|
| 5 |
# 使用 depth-anything + teed 生成外轮廓
|
| 6 |
# 使用 teed + 腐蚀算法 生成内边缘
|
|
|
|
|
|
|
| 7 |
from PIL import Image
|
| 8 |
+
|
| 9 |
import cv2
|
| 10 |
import numpy as np
|
| 11 |
import os
|
|
|
|
| 15 |
from tqdm import tqdm
|
| 16 |
import TEED.main as teed
|
| 17 |
from TEED.main import parse_args
|
|
|
|
|
|
|
| 18 |
|
| 19 |
from depthAnything.depth_anything.dpt import DepthAnything
|
| 20 |
from depthAnything.depth_anything.util.transform import Resize, NormalizeImage, PrepareForNet
|
| 21 |
import shutil
|
| 22 |
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
def multiply_blend(image1, image2):
|
| 25 |
# 将图片转换为浮点数,方便计算
|
|
|
|
| 352 |
|
| 353 |
|
| 354 |
if __name__ == '__main__':
|
| 355 |
+
# 原有的处理逻辑(如果需要)
|
| 356 |
+
# img_path = "input"
|
| 357 |
+
# outdir = "output"
|
| 358 |
+
# process_line(img_path, outdir)
|
| 359 |
|
| 360 |
+
# Gradio 接口代码
|
| 361 |
+
import gradio as gr
|
| 362 |
+
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
|
| 364 |
+
def gradio_process_line(img):
|
| 365 |
+
# 保存输入图像到临时文件
|
| 366 |
+
img_path = './temp_input.png'
|
| 367 |
+
img.save(img_path)
|
| 368 |
|
| 369 |
+
# 调用处理函数
|
| 370 |
+
process_line(img_path, './output')
|
| 371 |
+
|
| 372 |
+
# 返回输出图像
|
| 373 |
+
output_image_path = './output/merged_imgs/your_final_image_name.png' # 修改为实际输出路径
|
| 374 |
+
return Image.open(output_image_path)
|
| 375 |
+
|
| 376 |
+
# 定义 Gradio 接口
|
| 377 |
+
iface = gr.Interface(
|
| 378 |
+
fn=gradio_process_line,
|
| 379 |
+
inputs=gr.inputs.Image(type="pil"),
|
| 380 |
+
outputs="image",
|
| 381 |
+
title="Image Processing with Depth Anything and TEED",
|
| 382 |
+
description="Upload an image to process it with depth estimation and edge detection."
|
| 383 |
+
)
|
| 384 |
|
| 385 |
+
# 启动 Gradio 应用
|
| 386 |
+
iface.launch()
|
| 387 |
+
|
| 388 |
+
|
| 389 |
+
|