Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import cv2
|
|
5 |
import torch
|
6 |
from transformers import DPTFeatureExtractor, DPTForDepthEstimation
|
7 |
from fastapi import FastAPI, File, UploadFile, Response
|
8 |
-
from fastapi.responses import FileResponse
|
9 |
from PIL import Image
|
10 |
import uvicorn
|
11 |
|
@@ -54,13 +54,30 @@ async def analyze_path(file: UploadFile = File(...)):
|
|
54 |
end_time = time.time()
|
55 |
print(f"⏳ DPT xử lý trong {end_time - start_time:.4f} giây")
|
56 |
|
57 |
-
return {"message": "Depth Map processed successfully. View at /
|
58 |
|
59 |
@app.get("/depth_map/")
|
60 |
async def get_depth_map():
|
61 |
"""Trả về ảnh Depth Map để hiển thị trên trình duyệt"""
|
62 |
return FileResponse("depth_map.png", media_type="image/png")
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
# 🟢 Chạy server FastAPI trên Hugging Face Spaces
|
65 |
if __name__ == "__main__":
|
66 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
5 |
import torch
|
6 |
from transformers import DPTFeatureExtractor, DPTForDepthEstimation
|
7 |
from fastapi import FastAPI, File, UploadFile, Response
|
8 |
+
from fastapi.responses import FileResponse, HTMLResponse
|
9 |
from PIL import Image
|
10 |
import uvicorn
|
11 |
|
|
|
54 |
end_time = time.time()
|
55 |
print(f"⏳ DPT xử lý trong {end_time - start_time:.4f} giây")
|
56 |
|
57 |
+
return {"message": "Depth Map processed successfully. View at /view/"}
|
58 |
|
59 |
@app.get("/depth_map/")
|
60 |
async def get_depth_map():
|
61 |
"""Trả về ảnh Depth Map để hiển thị trên trình duyệt"""
|
62 |
return FileResponse("depth_map.png", media_type="image/png")
|
63 |
|
64 |
+
@app.get("/view/", response_class=HTMLResponse)
|
65 |
+
async def view_depth_map():
|
66 |
+
"""Trả về trang HTML để hiển thị ảnh Depth Map với auto-refresh"""
|
67 |
+
html_content = """
|
68 |
+
<html>
|
69 |
+
<head>
|
70 |
+
<title>Depth Map Viewer</title>
|
71 |
+
<meta http-equiv="refresh" content="5">
|
72 |
+
</head>
|
73 |
+
<body>
|
74 |
+
<h2>Depth Map (Tự động cập nhật mỗi 5 giây)</h2>
|
75 |
+
<img src="/depth_map/" width="500">
|
76 |
+
</body>
|
77 |
+
</html>
|
78 |
+
"""
|
79 |
+
return HTMLResponse(content=html_content)
|
80 |
+
|
81 |
# 🟢 Chạy server FastAPI trên Hugging Face Spaces
|
82 |
if __name__ == "__main__":
|
83 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|