Spaces:
Paused
Paused
Maksymilian Jankowski commited on
Commit ·
fcfd5ab
1
Parent(s): 8a258d8
fix timeouts
Browse files- main.py +34 -2
- routers/user_models.py +57 -8
main.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
import base64
|
| 3 |
-
from fastapi import FastAPI, UploadFile, File, HTTPException, Depends
|
| 4 |
import httpx
|
| 5 |
from contextlib import asynccontextmanager
|
| 6 |
from dotenv import load_dotenv
|
|
@@ -11,7 +11,7 @@ import logging
|
|
| 11 |
import random
|
| 12 |
from io import BytesIO
|
| 13 |
from urllib.parse import unquote
|
| 14 |
-
from fastapi.responses import StreamingResponse
|
| 15 |
import stripe
|
| 16 |
from typing import Optional
|
| 17 |
from routers import user_models
|
|
@@ -63,6 +63,7 @@ app.add_middleware(
|
|
| 63 |
allow_credentials=True,
|
| 64 |
allow_methods=["*"],
|
| 65 |
allow_headers=["*"],
|
|
|
|
| 66 |
)
|
| 67 |
|
| 68 |
# Pydantic models
|
|
@@ -902,6 +903,37 @@ async def debug_environment():
|
|
| 902 |
|
| 903 |
return debug_info
|
| 904 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 905 |
@app.get("/proxy/model", tags=["Proxy"])
|
| 906 |
async def proxy_model(url: str):
|
| 907 |
"""
|
|
|
|
| 1 |
import os
|
| 2 |
import base64
|
| 3 |
+
from fastapi import FastAPI, UploadFile, File, HTTPException, Depends, BackgroundTasks
|
| 4 |
import httpx
|
| 5 |
from contextlib import asynccontextmanager
|
| 6 |
from dotenv import load_dotenv
|
|
|
|
| 11 |
import random
|
| 12 |
from io import BytesIO
|
| 13 |
from urllib.parse import unquote
|
| 14 |
+
from fastapi.responses import StreamingResponse, JSONResponse
|
| 15 |
import stripe
|
| 16 |
from typing import Optional
|
| 17 |
from routers import user_models
|
|
|
|
| 63 |
allow_credentials=True,
|
| 64 |
allow_methods=["*"],
|
| 65 |
allow_headers=["*"],
|
| 66 |
+
expose_headers=["*"], # Ensure all headers are exposed to frontend
|
| 67 |
)
|
| 68 |
|
| 69 |
# Pydantic models
|
|
|
|
| 903 |
|
| 904 |
return debug_info
|
| 905 |
|
| 906 |
+
@app.post("/debug/test-background", tags=["Debug"])
|
| 907 |
+
async def test_background_response(background_tasks: BackgroundTasks):
|
| 908 |
+
"""Test endpoint to debug background task response issues"""
|
| 909 |
+
from fastapi.responses import JSONResponse
|
| 910 |
+
|
| 911 |
+
def dummy_background_task():
|
| 912 |
+
import time
|
| 913 |
+
time.sleep(1) # Simulate some work
|
| 914 |
+
logging.info("Background task completed")
|
| 915 |
+
|
| 916 |
+
# Add a background task
|
| 917 |
+
background_tasks.add_task(dummy_background_task)
|
| 918 |
+
|
| 919 |
+
response_data = {
|
| 920 |
+
"message": "Background task started",
|
| 921 |
+
"test_id": "test-123",
|
| 922 |
+
"status": "processing"
|
| 923 |
+
}
|
| 924 |
+
|
| 925 |
+
logging.info(f"Returning test response: {response_data}")
|
| 926 |
+
|
| 927 |
+
return JSONResponse(
|
| 928 |
+
content=response_data,
|
| 929 |
+
status_code=200,
|
| 930 |
+
headers={
|
| 931 |
+
"Content-Type": "application/json",
|
| 932 |
+
"Connection": "close",
|
| 933 |
+
"Cache-Control": "no-cache"
|
| 934 |
+
}
|
| 935 |
+
)
|
| 936 |
+
|
| 937 |
@app.get("/proxy/model", tags=["Proxy"])
|
| 938 |
async def proxy_model(url: str):
|
| 939 |
"""
|
routers/user_models.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
from fastapi import APIRouter, Depends, HTTPException, Request, BackgroundTasks, UploadFile, File, Form
|
|
|
|
| 2 |
from auth import get_current_active_user, User, supabase
|
| 3 |
import logging
|
| 4 |
import httpx
|
|
@@ -334,14 +335,26 @@ async def text_to_3d(prompt: TextPrompt, background_tasks: BackgroundTasks, curr
|
|
| 334 |
# Add background task for processing
|
| 335 |
background_tasks.add_task(_process_text_to_3d_background, generated_model_id, current_user.id, prompt.text)
|
| 336 |
|
| 337 |
-
# Return immediately
|
| 338 |
-
|
| 339 |
"generated_model_id": generated_model_id,
|
| 340 |
"status": "initializing",
|
| 341 |
"original_prompt": prompt.text,
|
| 342 |
"message": "Generation started. Use the progress_update endpoint to check status."
|
| 343 |
}
|
| 344 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
except Exception as ex:
|
| 346 |
logging.error(f"Failed to create initial model DB record: {ex}")
|
| 347 |
raise HTTPException(status_code=500, detail=f"Failed to start generation: {ex}")
|
|
@@ -383,14 +396,26 @@ async def image_to_3d(request: ImageTo3DRequest, background_tasks: BackgroundTas
|
|
| 383 |
# Add background task for Meshy API processing
|
| 384 |
background_tasks.add_task(_process_image_to_3d_background, generated_model_id, payload, "image_to_3d")
|
| 385 |
|
| 386 |
-
# Return immediately
|
| 387 |
-
|
| 388 |
"generated_model_id": generated_model_id,
|
| 389 |
"status": "initializing",
|
| 390 |
"input_image_url": request.image_url,
|
| 391 |
"message": "Generation started. Use the progress_update endpoint to check status."
|
| 392 |
}
|
| 393 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 394 |
except Exception as ex:
|
| 395 |
logging.error(f"Failed to create initial model DB record: {ex}")
|
| 396 |
raise HTTPException(status_code=500, detail=f"Failed to start generation: {ex}")
|
|
@@ -449,14 +474,26 @@ async def image_to_3d_upload(
|
|
| 449 |
# Add background task for Meshy API processing
|
| 450 |
background_tasks.add_task(_process_image_to_3d_background, generated_model_id, payload, "image_to_3d")
|
| 451 |
|
| 452 |
-
# Return immediately
|
| 453 |
-
|
| 454 |
"generated_model_id": generated_model_id,
|
| 455 |
"status": "initializing",
|
| 456 |
"input_image_filename": file.filename,
|
| 457 |
"message": "Generation started. Use the progress_update endpoint to check status."
|
| 458 |
}
|
| 459 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 460 |
except Exception as ex:
|
| 461 |
logging.error(f"Failed to create initial model DB record: {ex}")
|
| 462 |
raise HTTPException(status_code=500, detail=f"Failed to start generation: {ex}")
|
|
@@ -524,14 +561,26 @@ async def multi_image_to_3d_upload(
|
|
| 524 |
# Add background task for Meshy API processing
|
| 525 |
background_tasks.add_task(_process_image_to_3d_background, generated_model_id, payload, "multi_image_to_3d")
|
| 526 |
|
| 527 |
-
# Return immediately
|
| 528 |
-
|
| 529 |
"generated_model_id": generated_model_id,
|
| 530 |
"status": "initializing",
|
| 531 |
"input_image_filenames": filenames,
|
| 532 |
"message": "Generation started. Use the progress_update endpoint to check status."
|
| 533 |
}
|
| 534 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 535 |
except Exception as ex:
|
| 536 |
logging.error(f"Failed to create initial model DB record: {ex}")
|
| 537 |
raise HTTPException(status_code=500, detail=f"Failed to start generation: {ex}")
|
|
|
|
| 1 |
from fastapi import APIRouter, Depends, HTTPException, Request, BackgroundTasks, UploadFile, File, Form
|
| 2 |
+
from fastapi.responses import JSONResponse
|
| 3 |
from auth import get_current_active_user, User, supabase
|
| 4 |
import logging
|
| 5 |
import httpx
|
|
|
|
| 335 |
# Add background task for processing
|
| 336 |
background_tasks.add_task(_process_text_to_3d_background, generated_model_id, current_user.id, prompt.text)
|
| 337 |
|
| 338 |
+
# Return immediately with explicit headers
|
| 339 |
+
response_data = {
|
| 340 |
"generated_model_id": generated_model_id,
|
| 341 |
"status": "initializing",
|
| 342 |
"original_prompt": prompt.text,
|
| 343 |
"message": "Generation started. Use the progress_update endpoint to check status."
|
| 344 |
}
|
| 345 |
|
| 346 |
+
logging.info(f"Returning response for text-to-3d: {response_data}")
|
| 347 |
+
|
| 348 |
+
return JSONResponse(
|
| 349 |
+
content=response_data,
|
| 350 |
+
status_code=200,
|
| 351 |
+
headers={
|
| 352 |
+
"Content-Type": "application/json",
|
| 353 |
+
"Connection": "close",
|
| 354 |
+
"Cache-Control": "no-cache"
|
| 355 |
+
}
|
| 356 |
+
)
|
| 357 |
+
|
| 358 |
except Exception as ex:
|
| 359 |
logging.error(f"Failed to create initial model DB record: {ex}")
|
| 360 |
raise HTTPException(status_code=500, detail=f"Failed to start generation: {ex}")
|
|
|
|
| 396 |
# Add background task for Meshy API processing
|
| 397 |
background_tasks.add_task(_process_image_to_3d_background, generated_model_id, payload, "image_to_3d")
|
| 398 |
|
| 399 |
+
# Return immediately with explicit headers
|
| 400 |
+
response_data = {
|
| 401 |
"generated_model_id": generated_model_id,
|
| 402 |
"status": "initializing",
|
| 403 |
"input_image_url": request.image_url,
|
| 404 |
"message": "Generation started. Use the progress_update endpoint to check status."
|
| 405 |
}
|
| 406 |
|
| 407 |
+
logging.info(f"Returning response for image-to-3d: {response_data}")
|
| 408 |
+
|
| 409 |
+
return JSONResponse(
|
| 410 |
+
content=response_data,
|
| 411 |
+
status_code=200,
|
| 412 |
+
headers={
|
| 413 |
+
"Content-Type": "application/json",
|
| 414 |
+
"Connection": "close",
|
| 415 |
+
"Cache-Control": "no-cache"
|
| 416 |
+
}
|
| 417 |
+
)
|
| 418 |
+
|
| 419 |
except Exception as ex:
|
| 420 |
logging.error(f"Failed to create initial model DB record: {ex}")
|
| 421 |
raise HTTPException(status_code=500, detail=f"Failed to start generation: {ex}")
|
|
|
|
| 474 |
# Add background task for Meshy API processing
|
| 475 |
background_tasks.add_task(_process_image_to_3d_background, generated_model_id, payload, "image_to_3d")
|
| 476 |
|
| 477 |
+
# Return immediately with explicit headers
|
| 478 |
+
response_data = {
|
| 479 |
"generated_model_id": generated_model_id,
|
| 480 |
"status": "initializing",
|
| 481 |
"input_image_filename": file.filename,
|
| 482 |
"message": "Generation started. Use the progress_update endpoint to check status."
|
| 483 |
}
|
| 484 |
|
| 485 |
+
logging.info(f"Returning response for image-to-3d/upload: {response_data}")
|
| 486 |
+
|
| 487 |
+
return JSONResponse(
|
| 488 |
+
content=response_data,
|
| 489 |
+
status_code=200,
|
| 490 |
+
headers={
|
| 491 |
+
"Content-Type": "application/json",
|
| 492 |
+
"Connection": "close",
|
| 493 |
+
"Cache-Control": "no-cache"
|
| 494 |
+
}
|
| 495 |
+
)
|
| 496 |
+
|
| 497 |
except Exception as ex:
|
| 498 |
logging.error(f"Failed to create initial model DB record: {ex}")
|
| 499 |
raise HTTPException(status_code=500, detail=f"Failed to start generation: {ex}")
|
|
|
|
| 561 |
# Add background task for Meshy API processing
|
| 562 |
background_tasks.add_task(_process_image_to_3d_background, generated_model_id, payload, "multi_image_to_3d")
|
| 563 |
|
| 564 |
+
# Return immediately with explicit headers
|
| 565 |
+
response_data = {
|
| 566 |
"generated_model_id": generated_model_id,
|
| 567 |
"status": "initializing",
|
| 568 |
"input_image_filenames": filenames,
|
| 569 |
"message": "Generation started. Use the progress_update endpoint to check status."
|
| 570 |
}
|
| 571 |
|
| 572 |
+
logging.info(f"Returning response for multi-image-to-3d: {response_data}")
|
| 573 |
+
|
| 574 |
+
return JSONResponse(
|
| 575 |
+
content=response_data,
|
| 576 |
+
status_code=200,
|
| 577 |
+
headers={
|
| 578 |
+
"Content-Type": "application/json",
|
| 579 |
+
"Connection": "close",
|
| 580 |
+
"Cache-Control": "no-cache"
|
| 581 |
+
}
|
| 582 |
+
)
|
| 583 |
+
|
| 584 |
except Exception as ex:
|
| 585 |
logging.error(f"Failed to create initial model DB record: {ex}")
|
| 586 |
raise HTTPException(status_code=500, detail=f"Failed to start generation: {ex}")
|