Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,11 +13,33 @@ import subprocess
|
|
13 |
import shutil
|
14 |
import base64
|
15 |
import logging
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# Set up logging
|
18 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
19 |
logger = logging.getLogger(__name__)
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
# Install additional dependencies
|
22 |
try:
|
23 |
subprocess.run("pip install spandrel==0.4.1 --no-deps", shell=True, check=True)
|
@@ -384,6 +406,14 @@ def image_to_3d(
|
|
384 |
mesh_path = os.path.join(save_dir, f"polygenixai_{get_random_hex()}.glb")
|
385 |
mesh.export(mesh_path)
|
386 |
logger.info(f"Saved mesh to {mesh_path}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
387 |
|
388 |
torch.cuda.empty_cache()
|
389 |
return mesh_path
|
@@ -391,6 +421,8 @@ def image_to_3d(
|
|
391 |
logger.error(f"Error in image_to_3d: {str(e)}")
|
392 |
raise
|
393 |
|
|
|
|
|
394 |
@spaces.GPU(duration=5)
|
395 |
@torch.no_grad()
|
396 |
def run_texture(image: Image, mesh_path: str, seed: int, req: gr.Request):
|
|
|
13 |
import shutil
|
14 |
import base64
|
15 |
import logging
|
16 |
+
from fastapi import FastAPI
|
17 |
+
from fastapi.responses import JSONResponse
|
18 |
+
from fastapi.middleware.wsgi import WSGIMiddleware
|
19 |
+
import uvicorn
|
20 |
+
|
21 |
+
# Job status dictionary
|
22 |
+
generation_status = {}
|
23 |
+
|
24 |
|
25 |
# Set up logging
|
26 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
27 |
logger = logging.getLogger(__name__)
|
28 |
|
29 |
+
# FastAPI app to wrap both Gradio and API routes
|
30 |
+
api_app = FastAPI()
|
31 |
+
|
32 |
+
@api_app.get("/generation_status/{job_id}")
|
33 |
+
async def check_generation_status(job_id: str):
|
34 |
+
if job_id in generation_status:
|
35 |
+
return JSONResponse(content=generation_status[job_id])
|
36 |
+
else:
|
37 |
+
return JSONResponse(content={"status": "not_found"}, status_code=404)
|
38 |
+
|
39 |
+
|
40 |
+
# Mount the Gradio Blocks demo interface as WSGI
|
41 |
+
api_app.mount("/", WSGIMiddleware(demo))
|
42 |
+
|
43 |
# Install additional dependencies
|
44 |
try:
|
45 |
subprocess.run("pip install spandrel==0.4.1 --no-deps", shell=True, check=True)
|
|
|
406 |
mesh_path = os.path.join(save_dir, f"polygenixai_{get_random_hex()}.glb")
|
407 |
mesh.export(mesh_path)
|
408 |
logger.info(f"Saved mesh to {mesh_path}")
|
409 |
+
|
410 |
+
# Track job status
|
411 |
+
job_id = req.session_hash
|
412 |
+
generation_status[job_id] = {
|
413 |
+
"status": "ready",
|
414 |
+
"mesh_path": mesh_path
|
415 |
+
}
|
416 |
+
|
417 |
|
418 |
torch.cuda.empty_cache()
|
419 |
return mesh_path
|
|
|
421 |
logger.error(f"Error in image_to_3d: {str(e)}")
|
422 |
raise
|
423 |
|
424 |
+
|
425 |
+
|
426 |
@spaces.GPU(duration=5)
|
427 |
@torch.no_grad()
|
428 |
def run_texture(image: Image, mesh_path: str, seed: int, req: gr.Request):
|