Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- api/index.py +26 -26
api/index.py
CHANGED
@@ -101,36 +101,36 @@ def image_classifier(moodboard, starter_image, image_strength, prompt):
|
|
101 |
raise gr.Error(f"Please upload a moodboard to control image generation style")
|
102 |
|
103 |
# Call Stable Diffusion API with the response from OpenAI
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
|
128 |
-
#
|
129 |
-
|
130 |
-
|
131 |
|
132 |
-
|
133 |
|
134 |
-
header = "Set up APIs on HuggingFace or use free at https://app.idai.tools/"
|
135 |
demo = gr.Interface(fn=image_classifier, inputs=["image", "image", gr.Slider(0, 1, step=0.05, value=0.2, label="Image Strength"), "text"], outputs=["image", "image", "image"], title=header)
|
136 |
demo.launch(share=False)
|
|
|
101 |
raise gr.Error(f"Please upload a moodboard to control image generation style")
|
102 |
|
103 |
# Call Stable Diffusion API with the response from OpenAI
|
104 |
+
input = {
|
105 |
+
"width": 768,
|
106 |
+
"height": 768,
|
107 |
+
"prompt": "high quality render of " + prompt + ", " + openai_response[12:],
|
108 |
+
"negative_prompt": "worst quality, low quality, illustration, 2d, painting, cartoons, sketch",
|
109 |
+
"refine": "expert_ensemble_refiner",
|
110 |
+
"image": "data:image/jpeg;base64," + starter_image_base64,
|
111 |
+
"apply_watermark": False,
|
112 |
+
"num_inference_steps": 25,
|
113 |
+
"prompt_strength": 1-image_strength,
|
114 |
+
"num_outputs": 3
|
115 |
+
}
|
116 |
|
117 |
+
output = replicate.run(
|
118 |
+
"stability-ai/sdxl:7762fd07cf82c948538e41f63f77d685e02b063e37e496e96eefd46c929f9bdc",
|
119 |
+
input=input
|
120 |
+
)
|
121 |
|
122 |
+
images = []
|
123 |
+
for i in range(min(len(output), 3)):
|
124 |
+
image_url = output[i]
|
125 |
+
response = requests.get(image_url)
|
126 |
+
images.append(Image.open(io.BytesIO(response.content)))
|
127 |
|
128 |
+
# Add empty images if fewer than 3 were returned
|
129 |
+
while len(images) < 3:
|
130 |
+
images.append(Image.new('RGB', (768, 768), 'gray'))
|
131 |
|
132 |
+
return images
|
133 |
|
134 |
+
header = "Set up APIs on HuggingFace or use free at https://app.idai.tools/ (https://app.idai.tools/interface/moodboard_controlled)"
|
135 |
demo = gr.Interface(fn=image_classifier, inputs=["image", "image", gr.Slider(0, 1, step=0.05, value=0.2, label="Image Strength"), "text"], outputs=["image", "image", "image"], title=header)
|
136 |
demo.launch(share=False)
|