sushilideaclan01 commited on
Commit
a18335a
·
1 Parent(s): 8454aa1

Fix: Use Response instead of StreamingResponse for better HF compatibility

Browse files
Files changed (1) hide show
  1. main.py +10 -6
main.py CHANGED
@@ -334,16 +334,20 @@ async def root():
334
  try:
335
  async with httpx.AsyncClient(timeout=30.0) as client:
336
  response = await client.get("http://localhost:3000/")
337
- return StreamingResponse(
338
- response.iter_bytes(),
 
 
339
  status_code=response.status_code,
340
- headers=dict(response.headers),
341
  media_type=response.headers.get("content-type"),
342
  )
343
  except httpx.RequestError:
344
- raise HTTPException(
345
- status_code=503,
346
- detail="Frontend server is not available."
 
 
347
  )
348
 
349
 
 
334
  try:
335
  async with httpx.AsyncClient(timeout=30.0) as client:
336
  response = await client.get("http://localhost:3000/")
337
+ # Return full response (not streaming) for better HF compatibility
338
+ from fastapi.responses import Response
339
+ return Response(
340
+ content=response.content,
341
  status_code=response.status_code,
342
+ headers={k: v for k, v in response.headers.items() if k.lower() not in ['content-encoding', 'transfer-encoding', 'content-length']},
343
  media_type=response.headers.get("content-type"),
344
  )
345
  except httpx.RequestError:
346
+ # Return a simple HTML page if frontend is not ready yet
347
+ return Response(
348
+ content="<html><head><meta http-equiv='refresh' content='2'></head><body><h1>Loading...</h1></body></html>",
349
+ status_code=200,
350
+ media_type="text/html"
351
  )
352
 
353