Toy commited on
Commit
f83c585
Β·
1 Parent(s): df7e5d4

Add more logging

Browse files
Files changed (1) hide show
  1. app.py +28 -2
app.py CHANGED
@@ -281,7 +281,10 @@ def analyze_and_generate_french_style(image):
281
  return None, "Model not loaded", ""
282
 
283
  try:
 
 
284
  # Identify flower
 
285
  results = zs_classifier(
286
  image,
287
  candidate_labels=FLOWER_LABELS,
@@ -290,19 +293,28 @@ def analyze_and_generate_french_style(image):
290
 
291
  top_flower = results[0]["label"] if results else "flower"
292
  confidence = results[0]["score"] if results else 0
 
293
 
294
  # Extract dominant colors
 
 
295
  color_names, color_rgb = extract_dominant_colors(image, num_colors=3)
296
 
297
  # Create color description
298
  main_colors = color_names[:3] # Top 3 colors
299
  color_desc = ", ".join(main_colors)
 
300
 
301
  # Generate French-style prompt
 
302
  prompt = f"elegant French-style floral arrangement featuring {top_flower}s in {color_desc} colors, displayed in a clear crystal vase on a marble kitchen countertop, soft natural lighting, minimalist French country kitchen background, professional photography, sophisticated composition"
 
303
 
304
  # Generate the image
 
 
305
  generated_image = generate(prompt, steps=4, width=1024, height=1024, seed=-1)
 
306
 
307
  # Create analysis summary
308
  analysis = f"""
@@ -312,12 +324,20 @@ def analyze_and_generate_french_style(image):
312
 
313
  **πŸ‡«πŸ‡· Generated Prompt:**
314
  "{prompt}"
 
 
 
 
 
315
  """
316
 
317
  return generated_image, "βœ… Analysis complete! French-style arrangement generated.", analysis
318
 
319
  except Exception as e:
320
- return None, f"❌ Error: {str(e)}", ""
 
 
 
321
 
322
  # ---------- UI ----------
323
  with gr.Blocks() as demo:
@@ -403,8 +423,14 @@ with gr.Blocks() as demo:
403
  load_model_btn.click(load_trained_model, inputs=[model_dropdown], outputs=[model_status])
404
  train_btn.click(start_training, inputs=[epochs, batch_size, learning_rate], outputs=[training_output])
405
 
406
- # French Style tab events
 
 
 
407
  analyze_btn.click(
 
 
 
408
  analyze_and_generate_french_style,
409
  inputs=[upload_img],
410
  outputs=[french_result, french_status, analysis_details]
 
281
  return None, "Model not loaded", ""
282
 
283
  try:
284
+ progress_log = "πŸ”„ **Step 1/4:** Starting flower analysis...\n\n"
285
+
286
  # Identify flower
287
+ progress_log += "πŸ” Identifying flower type using AI model...\n"
288
  results = zs_classifier(
289
  image,
290
  candidate_labels=FLOWER_LABELS,
 
293
 
294
  top_flower = results[0]["label"] if results else "flower"
295
  confidence = results[0]["score"] if results else 0
296
+ progress_log += f"βœ… Identified: **{top_flower}** (confidence: {confidence:.2%})\n\n"
297
 
298
  # Extract dominant colors
299
+ progress_log += "πŸ”„ **Step 2/4:** Analyzing color palette...\n\n"
300
+ progress_log += "🎨 Extracting dominant colors from image...\n"
301
  color_names, color_rgb = extract_dominant_colors(image, num_colors=3)
302
 
303
  # Create color description
304
  main_colors = color_names[:3] # Top 3 colors
305
  color_desc = ", ".join(main_colors)
306
+ progress_log += f"βœ… Color palette: **{color_desc}**\n\n"
307
 
308
  # Generate French-style prompt
309
+ progress_log += "πŸ”„ **Step 3/4:** Creating French-style arrangement prompt...\n\n"
310
  prompt = f"elegant French-style floral arrangement featuring {top_flower}s in {color_desc} colors, displayed in a clear crystal vase on a marble kitchen countertop, soft natural lighting, minimalist French country kitchen background, professional photography, sophisticated composition"
311
+ progress_log += f"βœ… Prompt created: *{prompt[:100]}...*\n\n"
312
 
313
  # Generate the image
314
+ progress_log += "πŸ”„ **Step 4/4:** Generating French-style arrangement image...\n\n"
315
+ progress_log += "πŸ–ΌοΈ Using AI image generation (SDXL-Turbo)...\n"
316
  generated_image = generate(prompt, steps=4, width=1024, height=1024, seed=-1)
317
+ progress_log += "βœ… French-style arrangement generated successfully!\n\n"
318
 
319
  # Create analysis summary
320
  analysis = f"""
 
324
 
325
  **πŸ‡«πŸ‡· Generated Prompt:**
326
  "{prompt}"
327
+
328
+ ---
329
+
330
+ **πŸ“‹ Process Log:**
331
+ {progress_log}
332
  """
333
 
334
  return generated_image, "βœ… Analysis complete! French-style arrangement generated.", analysis
335
 
336
  except Exception as e:
337
+ error_log = f"❌ **Error occurred during processing:**\n\n{str(e)}\n\n"
338
+ if 'progress_log' in locals():
339
+ error_log += f"**Progress before error:**\n{progress_log}"
340
+ return None, f"❌ Error: {str(e)}", error_log
341
 
342
  # ---------- UI ----------
343
  with gr.Blocks() as demo:
 
423
  load_model_btn.click(load_trained_model, inputs=[model_dropdown], outputs=[model_status])
424
  train_btn.click(start_training, inputs=[epochs, batch_size, learning_rate], outputs=[training_output])
425
 
426
+ # French Style tab events - update status during processing
427
+ def update_french_status():
428
+ return "πŸ”„ Processing... Please wait while we analyze your flower image...", ""
429
+
430
  analyze_btn.click(
431
+ update_french_status,
432
+ outputs=[french_status, analysis_details]
433
+ ).then(
434
  analyze_and_generate_french_style,
435
  inputs=[upload_img],
436
  outputs=[french_result, french_status, analysis_details]