Mayur2 commited on
Commit
ce8b301
·
1 Parent(s): 5143b0e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -20
app.py CHANGED
@@ -116,30 +116,19 @@ 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
- input_string = responses.replace("\\n", "\n")
120
 
 
 
121
 
122
- # Remove unnecessary backslashes
123
- input_string = input_string.replace("\\", "")
124
-
125
- # Extract the desired string value
126
- output_string = input_string[input_string.find("Output :") + 9:]
127
-
128
- # Remove leading/trailing whitespace and double quotes
129
- output_string = output_string.strip().strip('"')
130
-
131
- # Split the string into key-value pairs
132
- output_list = [pair.strip() for pair in output_string.split("\\n")]
133
-
134
- # Create a dictionary from the key-value pairs
135
- output_dict = {}
136
- for pair in output_list:
137
  key, value = pair.split(":", 1)
138
- output_dict[key.strip()] = value.strip()
139
 
140
- # Convert the dictionary to JSON format
141
- json_output = json.dumps(output_dict, indent=4)
142
- print(json_output)
143
  # json_string = responses.strip()
144
 
145
  # # 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
+ split_pairs = string.split(" ")
120
 
121
+ # Initialize an empty dictionary to store the key-value pairs
122
+ key_value_dict = {}
123
 
124
+ # Iterate over each pair, splitting it further at the ":" character
125
+ for pair in split_pairs:
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  key, value = pair.split(":", 1)
127
+ key_value_dict[key.strip()] = value.strip()
128
 
129
+ # Print each key-value pair on a new line
130
+ for key, value in key_value_dict.items():
131
+ print("He",key + ": " + value)
132
  # json_string = responses.strip()
133
 
134
  # # Add indentation and new lines after each key-value pair