Spaces:
Running
Running
JV A commited on
Commit ·
d47faed
1
Parent(s): 0b1fd5e
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ def generate_image(prompt, negative_prompt, scheduler, steps, width, height, res
|
|
| 13 |
# Define the request headers
|
| 14 |
headers = {
|
| 15 |
"Content-Type": "application/json",
|
| 16 |
-
"token":
|
| 17 |
}
|
| 18 |
|
| 19 |
# Define the request body
|
|
@@ -24,7 +24,7 @@ def generate_image(prompt, negative_prompt, scheduler, steps, width, height, res
|
|
| 24 |
"batch_size": 1,
|
| 25 |
"prompt": prompt,
|
| 26 |
"negative_prompt": negative_prompt,
|
| 27 |
-
"seed": seed if seed else random.randint(0, 999999999),
|
| 28 |
"scheduler": scheduler,
|
| 29 |
"n_iter": 1,
|
| 30 |
"steps": steps,
|
|
@@ -69,13 +69,17 @@ def generate_image(prompt, negative_prompt, scheduler, steps, width, height, res
|
|
| 69 |
# Check the response status
|
| 70 |
if response.status_code == 200:
|
| 71 |
# Get the image URL from the response
|
| 72 |
-
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
|
| 78 |
-
|
|
|
|
|
|
|
| 79 |
else:
|
| 80 |
raise Exception("API request failed with status code " + str(response.status_code))
|
| 81 |
|
|
|
|
| 13 |
# Define the request headers
|
| 14 |
headers = {
|
| 15 |
"Content-Type": "application/json",
|
| 16 |
+
"token": token
|
| 17 |
}
|
| 18 |
|
| 19 |
# Define the request body
|
|
|
|
| 24 |
"batch_size": 1,
|
| 25 |
"prompt": prompt,
|
| 26 |
"negative_prompt": negative_prompt,
|
| 27 |
+
"seed": seed if seed is not None else random.randint(0, 999999999),
|
| 28 |
"scheduler": scheduler,
|
| 29 |
"n_iter": 1,
|
| 30 |
"steps": steps,
|
|
|
|
| 69 |
# Check the response status
|
| 70 |
if response.status_code == 200:
|
| 71 |
# Get the image URL from the response
|
| 72 |
+
response_json = response.json()
|
| 73 |
+
if 'results' in response_json and isinstance(response_json['results'], list) and len(response_json['results']) > 0:
|
| 74 |
+
image_url = response_json['results'][0]
|
| 75 |
|
| 76 |
+
# Get the image from the URL
|
| 77 |
+
image_response = requests.get(image_url)
|
| 78 |
+
image = PIL.Image.open(BytesIO(image_response.content))
|
| 79 |
|
| 80 |
+
return image
|
| 81 |
+
else:
|
| 82 |
+
raise Exception("Unexpected API response format")
|
| 83 |
else:
|
| 84 |
raise Exception("API request failed with status code " + str(response.status_code))
|
| 85 |
|