Update app.py
Browse files
app.py
CHANGED
|
@@ -114,6 +114,24 @@ def upload_and_process(image, promptText, promptImg, lens_option, n_images, size
|
|
| 114 |
# Remove backdrop
|
| 115 |
responses = chatgpt_chain.predict(human_input=promptText)
|
| 116 |
print(responses)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
dall_e_prompt = promptImg + " , " + lens_option
|
| 118 |
# Generate variations using DALL-E
|
| 119 |
removeBackdrop(image_path, "temp_no_bg.png")
|
|
@@ -123,7 +141,7 @@ def upload_and_process(image, promptText, promptImg, lens_option, n_images, size
|
|
| 123 |
# Get and return the images
|
| 124 |
result_images = outputGenImages(image_path, response_data)
|
| 125 |
|
| 126 |
-
text_output = f"<h2>{
|
| 127 |
|
| 128 |
return text_output, result_images # Output should be a list of PIL Image objects or numpy arrays
|
| 129 |
|
|
|
|
| 114 |
# Remove backdrop
|
| 115 |
responses = chatgpt_chain.predict(human_input=promptText)
|
| 116 |
print(responses)
|
| 117 |
+
json_string = responses.strip()
|
| 118 |
+
|
| 119 |
+
# Add indentation and new lines after each key-value pair
|
| 120 |
+
formatted_json = ''
|
| 121 |
+
indentation_level = 0
|
| 122 |
+
for char in json_string:
|
| 123 |
+
if char == '{' or char == '[':
|
| 124 |
+
formatted_json += char + '\n' + ' ' * indentation_level
|
| 125 |
+
indentation_level += 1
|
| 126 |
+
elif char == '}' or char == ']':
|
| 127 |
+
indentation_level -= 1
|
| 128 |
+
formatted_json += '\n' + ' ' * indentation_level + char
|
| 129 |
+
elif char == ',':
|
| 130 |
+
formatted_json += char + '\n' + ' ' * indentation_level
|
| 131 |
+
else:
|
| 132 |
+
formatted_json += char
|
| 133 |
+
|
| 134 |
+
print(formatted_json)
|
| 135 |
dall_e_prompt = promptImg + " , " + lens_option
|
| 136 |
# Generate variations using DALL-E
|
| 137 |
removeBackdrop(image_path, "temp_no_bg.png")
|
|
|
|
| 141 |
# Get and return the images
|
| 142 |
result_images = outputGenImages(image_path, response_data)
|
| 143 |
|
| 144 |
+
text_output = f"<h2>{formatted_json}</h2>"
|
| 145 |
|
| 146 |
return text_output, result_images # Output should be a list of PIL Image objects or numpy arrays
|
| 147 |
|