move coffee button to the description
Browse files
app.py
CHANGED
|
@@ -73,13 +73,6 @@ def hex_to_rgba(hex_color):
|
|
| 73 |
hex_color += 'FF' # Add full opacity if no alpha is provided
|
| 74 |
return tuple(int(hex_color[i:i + 2], 16) for i in (0, 2, 4, 6))
|
| 75 |
|
| 76 |
-
# Define the Buy Me a Coffee button HTML (moved inside the function for consistency)
|
| 77 |
-
bmc_button = """
|
| 78 |
-
<a href="https://coff.ee/rdjarbeng" target="_blank">
|
| 79 |
-
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-orange.png" alt="Buy Me a Coffee" style="height: 41px; width: 174px;">
|
| 80 |
-
</a>
|
| 81 |
-
"""
|
| 82 |
-
|
| 83 |
def remove_background(input_path, bg_color=None, transparent_bg=True, model_choice="", alpha_matting=False, post_process_mask=False, only_mask=False):
|
| 84 |
print(f"DEBUG: Function called with input_path: {input_path}")
|
| 85 |
print(f"DEBUG: Parameters - bg_color: {bg_color}, transparent_bg: {transparent_bg}, model_choice: {model_choice}")
|
|
@@ -88,7 +81,7 @@ def remove_background(input_path, bg_color=None, transparent_bg=True, model_choi
|
|
| 88 |
# Check if input path is valid
|
| 89 |
if not input_path or not os.path.exists(input_path):
|
| 90 |
print(f"ERROR: Invalid input path: {input_path}")
|
| 91 |
-
return None
|
| 92 |
|
| 93 |
print("DEBUG: Starting background removal...")
|
| 94 |
|
|
@@ -180,17 +173,17 @@ def remove_background(input_path, bg_color=None, transparent_bg=True, model_choi
|
|
| 180 |
if os.path.exists(output_path):
|
| 181 |
file_size = os.path.getsize(output_path)
|
| 182 |
print(f"DEBUG: Output file created successfully, size: {file_size} bytes")
|
| 183 |
-
return output_path
|
| 184 |
else:
|
| 185 |
print("ERROR: Output file was not created")
|
| 186 |
-
return None
|
| 187 |
|
| 188 |
except Exception as e:
|
| 189 |
print(f"ERROR: Exception occurred: {str(e)}")
|
| 190 |
import traceback
|
| 191 |
traceback.print_exc()
|
| 192 |
logging.error(f"An error occurred: {e}")
|
| 193 |
-
return None
|
| 194 |
|
| 195 |
# Fixed examples with proper values for all inputs
|
| 196 |
examples = [
|
|
@@ -215,7 +208,7 @@ iface = gr.Interface(
|
|
| 215 |
gr.Dropdown(
|
| 216 |
choices=[""] + [f"{k} | {v}" for k, v in MODEL_OPTIONS.items() if k != ""],
|
| 217 |
label="Model Selection",
|
| 218 |
-
value="",
|
| 219 |
allow_custom_value=False
|
| 220 |
),
|
| 221 |
gr.Checkbox(label="Enable Alpha Matting", value=False),
|
|
@@ -223,12 +216,17 @@ iface = gr.Interface(
|
|
| 223 |
gr.Checkbox(label="Only Return Mask", value=False)
|
| 224 |
],
|
| 225 |
outputs=[
|
| 226 |
-
gr.Image(type="filepath", label="Output Image (PNG)")
|
| 227 |
-
gr.HTML(label="Support This Project") # Added label for clarity
|
| 228 |
],
|
| 229 |
examples=examples,
|
| 230 |
title="Background Remover v2.9",
|
| 231 |
-
description=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
allow_flagging="never",
|
| 233 |
)
|
| 234 |
|
|
|
|
| 73 |
hex_color += 'FF' # Add full opacity if no alpha is provided
|
| 74 |
return tuple(int(hex_color[i:i + 2], 16) for i in (0, 2, 4, 6))
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
def remove_background(input_path, bg_color=None, transparent_bg=True, model_choice="", alpha_matting=False, post_process_mask=False, only_mask=False):
|
| 77 |
print(f"DEBUG: Function called with input_path: {input_path}")
|
| 78 |
print(f"DEBUG: Parameters - bg_color: {bg_color}, transparent_bg: {transparent_bg}, model_choice: {model_choice}")
|
|
|
|
| 81 |
# Check if input path is valid
|
| 82 |
if not input_path or not os.path.exists(input_path):
|
| 83 |
print(f"ERROR: Invalid input path: {input_path}")
|
| 84 |
+
return None
|
| 85 |
|
| 86 |
print("DEBUG: Starting background removal...")
|
| 87 |
|
|
|
|
| 173 |
if os.path.exists(output_path):
|
| 174 |
file_size = os.path.getsize(output_path)
|
| 175 |
print(f"DEBUG: Output file created successfully, size: {file_size} bytes")
|
| 176 |
+
return output_path
|
| 177 |
else:
|
| 178 |
print("ERROR: Output file was not created")
|
| 179 |
+
return None
|
| 180 |
|
| 181 |
except Exception as e:
|
| 182 |
print(f"ERROR: Exception occurred: {str(e)}")
|
| 183 |
import traceback
|
| 184 |
traceback.print_exc()
|
| 185 |
logging.error(f"An error occurred: {e}")
|
| 186 |
+
return None
|
| 187 |
|
| 188 |
# Fixed examples with proper values for all inputs
|
| 189 |
examples = [
|
|
|
|
| 208 |
gr.Dropdown(
|
| 209 |
choices=[""] + [f"{k} | {v}" for k, v in MODEL_OPTIONS.items() if k != ""],
|
| 210 |
label="Model Selection",
|
| 211 |
+
value="", # Changed from empty to match choices
|
| 212 |
allow_custom_value=False
|
| 213 |
),
|
| 214 |
gr.Checkbox(label="Enable Alpha Matting", value=False),
|
|
|
|
| 216 |
gr.Checkbox(label="Only Return Mask", value=False)
|
| 217 |
],
|
| 218 |
outputs=[
|
| 219 |
+
gr.Image(type="filepath", label="Output Image (PNG)")
|
|
|
|
| 220 |
],
|
| 221 |
examples=examples,
|
| 222 |
title="Background Remover v2.9",
|
| 223 |
+
description = """
|
| 224 |
+
Upload an image to remove the background. Choose a solid color or transparent background, select a model, and customize with alpha matting and other options. Right-click the output image to save as PNG.
|
| 225 |
+
If you would like to support this project:
|
| 226 |
+
<a href="https://coff.ee/rdjarbeng" target="_blank">
|
| 227 |
+
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-orange.png" alt="Buy Me a Coffee" style="height: 41px; width: 174px;">
|
| 228 |
+
</a>
|
| 229 |
+
""",
|
| 230 |
allow_flagging="never",
|
| 231 |
)
|
| 232 |
|