fffiloni commited on
Commit
6f44cc5
·
verified ·
1 Parent(s): 9dd43a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py CHANGED
@@ -180,6 +180,33 @@ def parse_perfume_description(text: str) -> dict:
180
 
181
  return result
182
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  def get_text_after_colon(input_text):
184
  # Find the first occurrence of ":"
185
  colon_index = input_text.find(":")
@@ -214,6 +241,9 @@ def infer(image_input):
214
 
215
  parsed = parse_perfume_description(result)
216
 
 
 
 
217
  return result, parsed
218
 
219
  css="""
 
180
 
181
  return result
182
 
183
+ def extract_image_description(response_json: str) -> str:
184
+ """
185
+ Extracts the Image Description value from a JSON response.
186
+
187
+ Args:
188
+ response_json (str): The JSON string returned by your LLM.
189
+
190
+ Returns:
191
+ str: The Image Description text.
192
+ """
193
+ try:
194
+ data = json.loads(response_json)
195
+ except json.JSONDecodeError:
196
+ raise ValueError("Invalid JSON string")
197
+
198
+ # The key might be 'Image Description' or 'image_description'
199
+ image_description = (
200
+ data.get("Image Description")
201
+ or data.get("image_description")
202
+ or None
203
+ )
204
+
205
+ if not image_description:
206
+ raise KeyError("No 'Image Description' field found in the JSON")
207
+
208
+ return image_description.strip()
209
+
210
  def get_text_after_colon(input_text):
211
  # Find the first occurrence of ":"
212
  colon_index = input_text.find(":")
 
241
 
242
  parsed = parse_perfume_description(result)
243
 
244
+ image_desc = extract_image_description(parsed)
245
+ print(image_desc)
246
+
247
  return result, parsed
248
 
249
  css="""