merasabkuch commited on
Commit
00658f1
·
verified ·
1 Parent(s): 00b35b6

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +5 -2
main.py CHANGED
@@ -180,9 +180,12 @@ async def analyze_image(file: UploadFile = File(...)):
180
  # Generate content using the AI model
181
  response = model.generate_content([prompt, blob])
182
 
183
- # Remove extra characters and escape sequences
184
- cleaned_response = re.sub(r'\\n|json', '', response.text).strip()
185
 
 
 
 
186
  # Parse the cleaned string as JSON
187
  data = json.loads(cleaned_response)
188
  fd = json.dumps(data, indent=4)
 
180
  # Generate content using the AI model
181
  response = model.generate_content([prompt, blob])
182
 
183
+ # Extract JSON string from Markdown-formatted JSON string
184
+ json_string = re.search(r'```json(.*?)```', response.text, re.DOTALL).group(1)
185
 
186
+ # Clean JSON string
187
+ cleaned_response = json_string.strip()
188
+
189
  # Parse the cleaned string as JSON
190
  data = json.loads(cleaned_response)
191
  fd = json.dumps(data, indent=4)