Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -136,36 +136,36 @@ def upload_image(url):
|
|
| 136 |
# raise HTTPException(status_code=500, detail=f"Failed to generate image: {str(e)}")
|
| 137 |
|
| 138 |
@app.post("/generate-image")
|
| 139 |
-
async def generate_image(request: ImageRequest):
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
|
|
|
| 164 |
}
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
raise HTTPException(status_code=500, detail=f"Failed to generate image: {str(e)}")
|
| 169 |
|
| 170 |
@app.get("/get-batches")
|
| 171 |
async def get_batches():
|
|
|
|
| 136 |
# raise HTTPException(status_code=500, detail=f"Failed to generate image: {str(e)}")
|
| 137 |
|
| 138 |
@app.post("/generate-image")
|
| 139 |
+
async def generate_image(request: ImageRequest):
|
| 140 |
+
print("Image Generation Request", request)
|
| 141 |
+
try:
|
| 142 |
+
runware = Runware(api_key=RUNWARE_API_KEY)
|
| 143 |
+
await runware.connect()
|
| 144 |
|
| 145 |
+
request_image = IImageInference(
|
| 146 |
+
positivePrompt=request.prompt,
|
| 147 |
+
model=request.model,
|
| 148 |
+
numberResults=request.number_results,
|
| 149 |
+
height=request.height,
|
| 150 |
+
width=request.width,
|
| 151 |
+
)
|
| 152 |
|
| 153 |
+
images = await runware.imageInference(requestImage=request_image)
|
| 154 |
+
image_urls = [image.imageURL for image in images]
|
| 155 |
+
print("Generated Images: ", image_urls)
|
| 156 |
|
| 157 |
+
response = {
|
| 158 |
+
"batch": {
|
| 159 |
+
"prompt": request.prompt,
|
| 160 |
+
"width": request.width,
|
| 161 |
+
"height": request.height,
|
| 162 |
+
"model": request.model,
|
| 163 |
+
"images": [{"url": url} for url in image_urls]
|
| 164 |
+
}
|
| 165 |
}
|
| 166 |
+
return response
|
| 167 |
+
except Exception as e:
|
| 168 |
+
raise HTTPException(status_code=500, detail=f"Failed to generate image: {str(e)}")
|
|
|
|
| 169 |
|
| 170 |
@app.get("/get-batches")
|
| 171 |
async def get_batches():
|