Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,8 +7,10 @@ from torchvision.transforms import Compose
|
|
| 7 |
import shutil
|
| 8 |
import os
|
| 9 |
|
|
|
|
| 10 |
from depthAnything.depth_anything.dpt import DepthAnything
|
| 11 |
from depthAnything.depth_anything.util.transform import Resize, NormalizeImage, PrepareForNet
|
|
|
|
| 12 |
|
| 13 |
# 保留原有图像处理函数如multiply_blend、screen_blend、erosion等
|
| 14 |
# 这些函数无需修改
|
|
@@ -61,24 +63,26 @@ def depth_anything_image(image, encoder='vitl', pred_only=True, grayscale=True):
|
|
| 61 |
return combined_results
|
| 62 |
|
| 63 |
# TEED function modified to process a single image
|
| 64 |
-
def teed_process_image(image
|
| 65 |
-
|
| 66 |
os.makedirs('teed_tmp', exist_ok=True)
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
img = cv2.GaussianBlur(img, (gaussianBlur[1], gaussianBlur[1]), gaussianBlur[2])
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
# Run TEED on the image
|
| 76 |
args, train_info = parse_args(is_testing=True, pl_opt_dir='./output/teed_imgs')
|
| 77 |
-
args.input_val_dir = 'teed_tmp' #
|
|
|
|
|
|
|
| 78 |
teed.main(args, train_info)
|
| 79 |
|
| 80 |
-
|
| 81 |
-
shutil.rmtree('teed_tmp')
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
return processed_image
|
| 84 |
|
|
@@ -97,8 +101,15 @@ def process_single_image(image):
|
|
| 97 |
|
| 98 |
# Gradio界面处理函数
|
| 99 |
def gradio_process_line(img):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
processed_image = process_single_image(img)
|
| 101 |
-
|
|
|
|
|
|
|
| 102 |
|
| 103 |
# Gradio 界面
|
| 104 |
import gradio as gr
|
|
|
|
| 7 |
import shutil
|
| 8 |
import os
|
| 9 |
|
| 10 |
+
|
| 11 |
from depthAnything.depth_anything.dpt import DepthAnything
|
| 12 |
from depthAnything.depth_anything.util.transform import Resize, NormalizeImage, PrepareForNet
|
| 13 |
+
from TEED.main import parse_args
|
| 14 |
|
| 15 |
# 保留原有图像处理函数如multiply_blend、screen_blend、erosion等
|
| 16 |
# 这些函数无需修改
|
|
|
|
| 63 |
return combined_results
|
| 64 |
|
| 65 |
# TEED function modified to process a single image
|
| 66 |
+
def teed_process_image(image):
|
| 67 |
+
os.makedirs('./output/teed_imgs', exist_ok=True)
|
| 68 |
os.makedirs('teed_tmp', exist_ok=True)
|
| 69 |
|
| 70 |
+
# 将图像保存为临时文件
|
| 71 |
+
temp_image_path = './teed_tmp/temp_image.png'
|
| 72 |
+
cv2.imwrite(temp_image_path, np.array(image))
|
|
|
|
| 73 |
|
| 74 |
+
# 设置 TEED 处理所需的参数
|
|
|
|
|
|
|
| 75 |
args, train_info = parse_args(is_testing=True, pl_opt_dir='./output/teed_imgs')
|
| 76 |
+
args.input_val_dir = './teed_tmp' # 临时目录
|
| 77 |
+
|
| 78 |
+
# 调用 TEED 主函数进行处理
|
| 79 |
teed.main(args, train_info)
|
| 80 |
|
| 81 |
+
# 清理临时文件
|
| 82 |
+
shutil.rmtree('teed_tmp')
|
| 83 |
+
|
| 84 |
+
return cv2.imread(os.path.join('./output/teed_imgs', 'processed_image.png'))
|
| 85 |
+
|
| 86 |
|
| 87 |
return processed_image
|
| 88 |
|
|
|
|
| 101 |
|
| 102 |
# Gradio界面处理函数
|
| 103 |
def gradio_process_line(img):
|
| 104 |
+
# 保存上传的图像到临时路径
|
| 105 |
+
img_path = './temp_input.png'
|
| 106 |
+
img.save(img_path)
|
| 107 |
+
|
| 108 |
+
# 处理图像
|
| 109 |
processed_image = process_single_image(img)
|
| 110 |
+
|
| 111 |
+
# 返回处理后的图像
|
| 112 |
+
return Image.fromarray(processed_image)
|
| 113 |
|
| 114 |
# Gradio 界面
|
| 115 |
import gradio as gr
|