Spaces:
Running
on
Zero
Running
on
Zero
Add error handling to caption and focus generation functions in app_v4.py for improved robustness
Browse files
app_v4.py
CHANGED
|
@@ -77,34 +77,46 @@ def generate_image(prompt, scale, steps, control_image, controlnet_conditioning_
|
|
| 77 |
return image
|
| 78 |
|
| 79 |
def combine_caption_focus(caption, focus):
|
| 80 |
-
|
| 81 |
-
caption
|
| 82 |
-
|
| 83 |
-
focus
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
def generate_caption(control_image):
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
def generate_focus(control_image, focus_list):
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
| 106 |
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
def process_image(control_image, user_prompt, system_prompt, scale, steps,
|
| 110 |
controlnet_conditioning_scale, guidance_scale, seed,
|
|
|
|
| 77 |
return image
|
| 78 |
|
| 79 |
def combine_caption_focus(caption, focus):
|
| 80 |
+
try:
|
| 81 |
+
if caption is None:
|
| 82 |
+
caption = ""
|
| 83 |
+
if focus is None:
|
| 84 |
+
focus = "highly detailed photo, raw photography."
|
| 85 |
+
return (str(caption) + "\n\n" + str(focus)).strip()
|
| 86 |
+
except Exception as e:
|
| 87 |
+
print(f"Error combining caption and focus: {e}")
|
| 88 |
+
return "highly detailed photo, raw photography."
|
| 89 |
|
| 90 |
def generate_caption(control_image):
|
| 91 |
+
try:
|
| 92 |
+
if control_image is None:
|
| 93 |
+
return "Waiting for control image..."
|
| 94 |
+
|
| 95 |
+
# Generate a detailed caption
|
| 96 |
+
mcaption = model.caption(control_image, length="short")
|
| 97 |
+
detailed_caption = mcaption["caption"]
|
| 98 |
+
print(f"Detailed caption: {detailed_caption}")
|
| 99 |
+
|
| 100 |
+
return detailed_caption
|
| 101 |
+
except Exception as e:
|
| 102 |
+
print(f"Error generating caption: {e}")
|
| 103 |
+
return "A detailed photograph"
|
| 104 |
|
| 105 |
def generate_focus(control_image, focus_list):
|
| 106 |
+
try:
|
| 107 |
+
if control_image is None:
|
| 108 |
+
return None
|
| 109 |
+
if focus_list is None:
|
| 110 |
+
return ""
|
| 111 |
+
# Generate a detailed caption
|
| 112 |
+
focus_query = model.query(control_image, "Please provide a concise but illustrative description of the following area(s) of focus: " + focus_list)
|
| 113 |
+
focus_description = focus_query["answer"]
|
| 114 |
+
print(f"Areas of focus: {focus_description}")
|
| 115 |
|
| 116 |
+
return focus_description
|
| 117 |
+
except Exception as e:
|
| 118 |
+
print(f"Error generating focus: {e}")
|
| 119 |
+
return "highly detailed photo, raw photography."
|
| 120 |
|
| 121 |
def process_image(control_image, user_prompt, system_prompt, scale, steps,
|
| 122 |
controlnet_conditioning_scale, guidance_scale, seed,
|