Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,7 +28,7 @@ class Config:
|
|
| 28 |
|
| 29 |
class RunPodClient:
|
| 30 |
async def generate_image(self, prompt, negative_prompt=""):
|
| 31 |
-
"""Handles
|
| 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 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
return None, f"Could not
|
| 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)}")
|