Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- api/index.py +11 -21
api/index.py
CHANGED
@@ -112,8 +112,7 @@ def image_classifier(moodboard, starter_image, image_strength, prompt):
|
|
112 |
"apply_watermark": False,
|
113 |
"num_inference_steps": 25,
|
114 |
"prompt_strength": 1-image_strength,
|
115 |
-
"num_outputs": 3
|
116 |
-
"disable_safety_checker": True
|
117 |
}
|
118 |
|
119 |
output = replicate.run(
|
@@ -121,26 +120,17 @@ def image_classifier(moodboard, starter_image, image_strength, prompt):
|
|
121 |
input=input
|
122 |
)
|
123 |
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
img1 = Image.open(io.BytesIO(response.content))
|
130 |
-
|
131 |
-
image_url = output[1]
|
132 |
-
print(image_url)
|
133 |
-
response = requests.get(image_url)
|
134 |
-
print(response)
|
135 |
-
img2 = Image.open(io.BytesIO(response.content))
|
136 |
-
|
137 |
-
image_url = output[2]
|
138 |
-
print(image_url)
|
139 |
-
response = requests.get(image_url)
|
140 |
-
print(response)
|
141 |
-
img3 = Image.open(io.BytesIO(response.content))
|
142 |
|
143 |
-
|
|
|
|
|
|
|
|
|
144 |
|
145 |
demo = gr.Interface(fn=image_classifier, inputs=["image", "image", gr.Slider(0, 1, step=0.025, value=0.2, label="Image Strength"), "text"], outputs=["image", "image", "image"])
|
146 |
demo.launch(share=False)
|
|
|
112 |
"apply_watermark": False,
|
113 |
"num_inference_steps": 25,
|
114 |
"prompt_strength": 1-image_strength,
|
115 |
+
"num_outputs": 3
|
|
|
116 |
}
|
117 |
|
118 |
output = replicate.run(
|
|
|
120 |
input=input
|
121 |
)
|
122 |
|
123 |
+
images = []
|
124 |
+
for i in range(min(len(output), 3)):
|
125 |
+
image_url = output[i]
|
126 |
+
response = requests.get(image_url)
|
127 |
+
images.append(Image.open(io.BytesIO(response.content)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
+
# Add empty images if fewer than 3 were returned
|
130 |
+
while len(images) < 3:
|
131 |
+
images.append(Image.new('RGB', (768, 768), 'gray'))
|
132 |
+
|
133 |
+
return images
|
134 |
|
135 |
demo = gr.Interface(fn=image_classifier, inputs=["image", "image", gr.Slider(0, 1, step=0.025, value=0.2, label="Image Strength"), "text"], outputs=["image", "image", "image"])
|
136 |
demo.launch(share=False)
|