Update app.py
Browse files
app.py
CHANGED
|
@@ -116,10 +116,26 @@ def upload_and_process(image, promptText, promptImg, lens_option, n_images, size
|
|
| 116 |
# Remove backdrop
|
| 117 |
responses = chatgpt_chain.predict(human_input=promptText)
|
| 118 |
print(responses)
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
|
|
|
|
|
|
|
|
|
| 123 |
# json_string = responses.strip()
|
| 124 |
|
| 125 |
# # Add indentation and new lines after each key-value pair
|
|
|
|
| 116 |
# Remove backdrop
|
| 117 |
responses = chatgpt_chain.predict(human_input=promptText)
|
| 118 |
print(responses)
|
| 119 |
+
input_string = input_string.replace("\\n", "\n")
|
| 120 |
+
|
| 121 |
+
# Remove unnecessary backslashes
|
| 122 |
+
input_string = input_string.replace("\\", "")
|
| 123 |
+
|
| 124 |
+
# Extract the desired string value
|
| 125 |
+
output_string = input_string[input_string.find("Output :") + 9:]
|
| 126 |
+
|
| 127 |
+
# Remove leading/trailing whitespace and double quotes
|
| 128 |
+
output_string = output_string.strip().strip('"')
|
| 129 |
+
|
| 130 |
+
# Split the string into key-value pairs
|
| 131 |
+
output_list = [pair.strip() for pair in output_string.split("\\n")]
|
| 132 |
+
|
| 133 |
+
# Create a dictionary from the key-value pairs
|
| 134 |
+
output_dict = dict(pair.split(":") for pair in output_list)
|
| 135 |
|
| 136 |
+
# Convert the dictionary to JSON format
|
| 137 |
+
json_output = json.dumps(output_dict, indent=4)
|
| 138 |
+
print(json_output)
|
| 139 |
# json_string = responses.strip()
|
| 140 |
|
| 141 |
# # Add indentation and new lines after each key-value pair
|