Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,8 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
| 3 |
from inference import ObjectDetector
|
| 4 |
import numpy as np
|
| 5 |
import cv2
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Configuration
|
| 8 |
MODEL_ONNX_PATH = "model.onnx"
|
|
@@ -55,6 +57,11 @@ app.add_middleware(
|
|
| 55 |
expose_headers=["*"]
|
| 56 |
)
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
@app.options("/detect")
|
| 59 |
async def detect_options():
|
| 60 |
return {"Allow": "POST"}
|
|
@@ -93,5 +100,7 @@ async def detect_objects(file: UploadFile = File(...)):
|
|
| 93 |
raise HTTPException(500, f"Processing error: {str(e)}")
|
| 94 |
|
| 95 |
if __name__ == "__main__":
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
|
|
| 3 |
from inference import ObjectDetector
|
| 4 |
import numpy as np
|
| 5 |
import cv2
|
| 6 |
+
import socket
|
| 7 |
+
import uvicorn
|
| 8 |
|
| 9 |
# Configuration
|
| 10 |
MODEL_ONNX_PATH = "model.onnx"
|
|
|
|
| 57 |
expose_headers=["*"]
|
| 58 |
)
|
| 59 |
|
| 60 |
+
def get_base_url():
|
| 61 |
+
hostname = socket.gethostname()
|
| 62 |
+
port = 7860 # Hugging Face Spaces uses port 7860
|
| 63 |
+
return f"https://{hostname}.hf.space"
|
| 64 |
+
|
| 65 |
@app.options("/detect")
|
| 66 |
async def detect_options():
|
| 67 |
return {"Allow": "POST"}
|
|
|
|
| 100 |
raise HTTPException(500, f"Processing error: {str(e)}")
|
| 101 |
|
| 102 |
if __name__ == "__main__":
|
| 103 |
+
base_url = get_base_url()
|
| 104 |
+
print(f"Base URL: {base_url}")
|
| 105 |
+
print(f"API endpoint: {base_url}/detect")
|
| 106 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|