Spaces:
Paused

knnn11 commited on
Commit
24bb578
·
verified ·
1 Parent(s): f4f3664

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -15
app.py CHANGED
@@ -28,7 +28,7 @@ class Config:
28
 
29
  class RunPodClient:
30
  async def generate_image(self, prompt, negative_prompt=""):
31
- """Handles the exact response format from your RunPod endpoint"""
32
  Config.validate_config()
33
 
34
  payload = {
@@ -38,7 +38,8 @@ class RunPodClient:
38
  "width": Config.IMAGE_SIZE[0],
39
  "height": Config.IMAGE_SIZE[1],
40
  "steps": 25,
41
- "guidance_scale": 7.5
 
42
  }
43
  }
44
 
@@ -57,23 +58,32 @@ class RunPodClient:
57
 
58
  # Handle your specific response format
59
  if isinstance(data, dict) and data.get("status") == "COMPLETED":
 
 
 
 
 
60
  endpoint_id = Config.RUNPOD_ENDPOINT.split('/')[-2]
61
- worker_id = data.get("workerId")
62
  job_id = data.get("id")
63
 
64
- # Construct the direct image URL (RunPod standard location)
65
- image_url = f"https://api.runpod.ai/v2/{endpoint_id}/worker/output/{worker_id}/{job_id}/0.png"
66
-
67
- # Verify the URL exists
68
- async with session.head(
69
- image_url,
70
- headers={"Authorization": f"Bearer {Config.RUNPOD_API_KEY}"},
71
- timeout=10
72
- ) as head_response:
73
- if head_response.status == 200:
74
- return image_url, None
 
 
 
 
 
75
 
76
- return None, f"Could not construct image URL from response: {data}"
77
 
78
  except Exception as e:
79
  logger.error(f"API request failed: {str(e)}")
 
28
 
29
  class RunPodClient:
30
  async def generate_image(self, prompt, negative_prompt=""):
31
+ """Handles all possible RunPod response formats"""
32
  Config.validate_config()
33
 
34
  payload = {
 
38
  "width": Config.IMAGE_SIZE[0],
39
  "height": Config.IMAGE_SIZE[1],
40
  "steps": 25,
41
+ "guidance_scale": 7.5,
42
+ "enable_image_upload": True # Ensure image upload is enabled
43
  }
44
  }
45
 
 
58
 
59
  # Handle your specific response format
60
  if isinstance(data, dict) and data.get("status") == "COMPLETED":
61
+ # Method 1: Check for direct output URL
62
+ if isinstance(data.get("output"), list) and len(data["output"]) > 0:
63
+ return data["output"][0], None
64
+
65
+ # Method 2: Construct URL from job details
66
  endpoint_id = Config.RUNPOD_ENDPOINT.split('/')[-2]
 
67
  job_id = data.get("id")
68
 
69
+ if job_id:
70
+ # Try different URL patterns
71
+ url_patterns = [
72
+ f"https://api.runpod.ai/v2/{endpoint_id}/output/{job_id}/0.png",
73
+ f"https://api.runpod.ai/v2/{endpoint_id}/files/{job_id}/0.png",
74
+ f"https://api.runpod.ai/v2/{endpoint_id}/results/{job_id}/0.png"
75
+ ]
76
+
77
+ for url in url_patterns:
78
+ async with session.head(
79
+ url,
80
+ headers={"Authorization": f"Bearer {Config.RUNPOD_API_KEY}"},
81
+ timeout=10
82
+ ) as head_response:
83
+ if head_response.status == 200:
84
+ return url, None
85
 
86
+ return None, f"Could not determine image location from response: {data}"
87
 
88
  except Exception as e:
89
  logger.error(f"API request failed: {str(e)}")