adpro commited on
Commit
1b0fc86
·
verified ·
1 Parent(s): 6205c6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -1
app.py CHANGED
@@ -3,10 +3,12 @@ import time
3
  import numpy as np
4
  import cv2
5
  import torch
 
6
  from transformers import DPTFeatureExtractor, DPTForDepthEstimation
7
  from fastapi import FastAPI, File, UploadFile
8
  from PIL import Image
9
  import uvicorn
 
10
 
11
  # 🟢 Tạo FastAPI
12
  app = FastAPI()
@@ -83,6 +85,29 @@ def detect_path(depth_map):
83
  else:
84
  return "backward"
85
 
86
- # 🟢 Chạy server FastAPI
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  if __name__ == "__main__":
 
 
 
 
88
  uvicorn.run(app, host="0.0.0.0", port=7860)
 
3
  import numpy as np
4
  import cv2
5
  import torch
6
+ import gradio as gr
7
  from transformers import DPTFeatureExtractor, DPTForDepthEstimation
8
  from fastapi import FastAPI, File, UploadFile
9
  from PIL import Image
10
  import uvicorn
11
+ import threading
12
 
13
  # 🟢 Tạo FastAPI
14
  app = FastAPI()
 
85
  else:
86
  return "backward"
87
 
88
+ # 🟢 Hàm Gradio hiển thị ảnh Depth Map
89
+ def get_depth_map():
90
+ """Trả về ảnh Depth Map mới nhất từ FastAPI"""
91
+ try:
92
+ return Image.open("depth_map.png") # 🟢 Lấy ảnh đã lưu từ FastAPI
93
+ except FileNotFoundError:
94
+ return "Chưa có ảnh Depth Map nào được xử lý!"
95
+
96
+ # 🟢 Tạo giao diện Gradio trên Hugging Face Spaces
97
+ def launch_gradio():
98
+ gr.Interface(
99
+ fn=get_depth_map,
100
+ inputs=[],
101
+ outputs=gr.Image(type="pil"),
102
+ title="🔍 Depth Map Viewer",
103
+ description="Hiển thị ảnh Depth Map mới nhất từ FastAPI",
104
+ live=True, # 🎯 **Tự động cập nhật ảnh mới**
105
+ ).launch(share=True)
106
+
107
+ # 🟢 Chạy cả FastAPI và Gradio cùng lúc
108
  if __name__ == "__main__":
109
+ # Chạy Gradio trong một luồng riêng
110
+ threading.Thread(target=launch_gradio, daemon=True).start()
111
+
112
+ # Chạy FastAPI
113
  uvicorn.run(app, host="0.0.0.0", port=7860)