Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- api/index.py +32 -30
api/index.py
CHANGED
@@ -25,6 +25,7 @@ client = OpenAI()
|
|
25 |
|
26 |
def call_openai(pil_image):
|
27 |
# Save the PIL image to a bytes buffer
|
|
|
28 |
buffered = io.BytesIO()
|
29 |
pil_image.save(buffered, format="JPEG")
|
30 |
|
@@ -62,7 +63,8 @@ def call_openai(pil_image):
|
|
62 |
raise gr.Error("Unknown Error")
|
63 |
|
64 |
def image_classifier(moodboard, starter_image, image_strength, prompt):
|
65 |
-
|
|
|
66 |
if moodboard is not None and starter_image is not None:
|
67 |
|
68 |
# Convert the numpy array to a PIL image
|
@@ -84,10 +86,10 @@ def image_classifier(moodboard, starter_image, image_strength, prompt):
|
|
84 |
# Resize the image
|
85 |
starter_image_pil = starter_image_pil.resize((new_width, new_height), Image.LANCZOS)
|
86 |
|
87 |
-
openai_response = call_openai(pil_image)
|
88 |
-
openai_response = openai_response.replace('moodboard', '')
|
89 |
-
openai_response = openai_response.replace('share', '')
|
90 |
-
openai_response = openai_response.replace('unified', '')
|
91 |
|
92 |
# Save the starter image to a bytes buffer
|
93 |
buffered = io.BytesIO()
|
@@ -99,35 +101,35 @@ def image_classifier(moodboard, starter_image, image_strength, prompt):
|
|
99 |
raise gr.Error(f"Please upload a moodboard to control image generation style")
|
100 |
|
101 |
# Call Stable Diffusion API with the response from OpenAI
|
102 |
-
input = {
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
}
|
114 |
|
115 |
-
output = replicate.run(
|
116 |
-
|
117 |
-
|
118 |
-
)
|
119 |
|
120 |
-
images = []
|
121 |
-
for i in range(min(len(output), 3)):
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
|
126 |
-
# Add empty images if fewer than 3 were returned
|
127 |
-
while len(images) < 3:
|
128 |
-
|
129 |
|
130 |
-
return images
|
131 |
|
132 |
header = "Set up APIs on HuggingFace or use free at https://app.idai.tools/"
|
133 |
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)
|
|
|
25 |
|
26 |
def call_openai(pil_image):
|
27 |
# Save the PIL image to a bytes buffer
|
28 |
+
|
29 |
buffered = io.BytesIO()
|
30 |
pil_image.save(buffered, format="JPEG")
|
31 |
|
|
|
63 |
raise gr.Error("Unknown Error")
|
64 |
|
65 |
def image_classifier(moodboard, starter_image, image_strength, prompt):
|
66 |
+
raise gr.Error(header)
|
67 |
+
|
68 |
if moodboard is not None and starter_image is not None:
|
69 |
|
70 |
# Convert the numpy array to a PIL image
|
|
|
86 |
# Resize the image
|
87 |
starter_image_pil = starter_image_pil.resize((new_width, new_height), Image.LANCZOS)
|
88 |
|
89 |
+
#openai_response = call_openai(pil_image)
|
90 |
+
#openai_response = openai_response.replace('moodboard', '')
|
91 |
+
#openai_response = openai_response.replace('share', '')
|
92 |
+
#openai_response = openai_response.replace('unified', '')
|
93 |
|
94 |
# Save the starter image to a bytes buffer
|
95 |
buffered = io.BytesIO()
|
|
|
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/"
|
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)
|