adpro commited on
Commit
3bdfe12
·
verified ·
1 Parent(s): 78f1051

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -7
app.py CHANGED
@@ -19,14 +19,9 @@ feature_extractor = DPTFeatureExtractor.from_pretrained("Intel/dpt-swinv2-tiny-2
19
  model = DPTForDepthEstimation.from_pretrained("Intel/dpt-swinv2-tiny-256").to(device)
20
  model.eval()
21
 
22
- # 🟢 Biến lưu ảnh Depth Map để hiển thị trên Gradio
23
- depth_map_global = None
24
-
25
  @app.post("/analyze_path/")
26
  async def analyze_path(file: UploadFile = File(...)):
27
- """Xử lý ảnh Depth Map và trả về lệnh điều hướng"""
28
- global depth_map_global # Dùng biến toàn cục để hiển thị trên Gradio
29
-
30
  start_time = time.time()
31
 
32
  # 🟢 Đọc file ảnh từ ESP32
@@ -54,7 +49,7 @@ async def analyze_path(file: UploadFile = File(...)):
54
  depth_pil = Image.fromarray(depth_colored)
55
 
56
  # 🟢 Lưu ảnh Depth Map để hiển thị trên Gradio
57
- depth_map_global = depth_pil
58
 
59
  end_time = time.time()
60
  print(f"⏳ DPT xử lý trong {end_time - start_time:.4f} giây")
 
19
  model = DPTForDepthEstimation.from_pretrained("Intel/dpt-swinv2-tiny-256").to(device)
20
  model.eval()
21
 
 
 
 
22
  @app.post("/analyze_path/")
23
  async def analyze_path(file: UploadFile = File(...)):
24
+ """Xử lý ảnh Depth Map và lưu ảnh để hiển thị trên Hugging Face"""
 
 
25
  start_time = time.time()
26
 
27
  # 🟢 Đọc file ảnh từ ESP32
 
49
  depth_pil = Image.fromarray(depth_colored)
50
 
51
  # 🟢 Lưu ảnh Depth Map để hiển thị trên Gradio
52
+ depth_pil.save("depth_map.png") # 🎯 **Gradio sẽ truy cập ảnh này**
53
 
54
  end_time = time.time()
55
  print(f"⏳ DPT xử lý trong {end_time - start_time:.4f} giây")