plutosss commited on
Commit
c4503c1
·
verified ·
1 Parent(s): 440a7b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -28
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
- # depth_anything()
362
- # teed_imgs('./input', './output/teed_imgs', [1,7,2])
363
- # teed_imgs('./output/depth_anything', './output/dp_teed_imgs', [0,7,2])
364
- # merge_images_in_2_folder('./output/teed_imgs', './output/dp_teed_imgs', './output/merged_imgs','_depth', 1, 'multiply', [[2,0],[2,1]],[1,0])
365
 
366
- # erosion_img_from_path('./output/teed_imgs', './output/erosion_imgs', 2, 1, True)
367
- # guassian_blur_path('./input', './output/guassian_blur', 7, 2)
368
- # erosion_img_from_path('./output/merged_imgs', './output/erosion_merged_imgs', 2, 1, False)
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
- if __name__ == '__main__':
376
- # 创建 Gradio 接口
377
- interface = gr.Interface(fn=process_line,
378
- inputs=gr.Image(type="numpy", label="Upload Image"),
379
- outputs=gr.Image(label="Output Image"),
380
- title="Image Processing",
381
- description="Upload an image to process it using depth-anything and TEED.")
382
-
383
- # 启动 Gradio 接口
384
- interface.launch()
 
 
 
 
 
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
+