TSC4 commited on
Commit
74c568d
·
verified ·
1 Parent(s): d7066ea

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -1,5 +1,5 @@
1
  # -*- coding: utf-8 -*-
2
- """Untitled5.ipynb
3
 
4
  Automatically generated by Colab.
5
 
@@ -51,7 +51,8 @@ def remove_background_color(image, hex_color, tolerance):
51
  data[:, :, 3] = alpha_channel
52
  return data
53
 
54
- def color_remover_interface(image, hex_color, tolerance):
 
55
  """
56
  Gradio interface function for color removal.
57
  """
@@ -60,10 +61,10 @@ def color_remover_interface(image, hex_color, tolerance):
60
  raise ValueError("Please upload an image")
61
  hex_color = sanitize_hex_color(hex_color)
62
  processed_image = remove_background_color(image, hex_color, tolerance)
63
- return image, processed_image
64
  except Exception as e:
65
  gr.Warning(str(e))
66
- return image, image
67
 
68
  # Deploy using Gradio Client
69
  iface = gr.Interface(
@@ -71,23 +72,22 @@ iface = gr.Interface(
71
  inputs=[
72
  gr.Image(type="numpy", label="Upload Image"),
73
  gr.Textbox(label="Hex Color to Remove", placeholder="#FFFFFF"),
74
- gr.Slider(minimum=0, maximum=255, value=20, step=1, label="Color Tolerance")
 
75
  ],
76
  outputs=[
77
- gr.Image(type="numpy", label="Original Image"),
78
- gr.Image(type="numpy", label="Processed Image")
79
  ],
80
- title="Image Color Remover",
81
  description="""
82
- Remove a specific color from your image with precision!
83
 
84
  ### How to Use:
85
  1. Upload an image
86
- 2. Choose the color to remove
87
- 3. Adjust the color tolerance
88
  4. See the magic happen!
89
  """,
90
- # api_name="your-color-remover-app" # You can optionally set a custom API name
91
  )
92
 
93
  iface.launch(share=True) # Launch the interface with a shareable link
 
1
  # -*- coding: utf-8 -*-
2
+ """app code for remove.ipynb
3
 
4
  Automatically generated by Colab.
5
 
 
51
  data[:, :, 3] = alpha_channel
52
  return data
53
 
54
+
55
+ def color_remover_interface(image, hex_color, tolerance, _=None):
56
  """
57
  Gradio interface function for color removal.
58
  """
 
61
  raise ValueError("Please upload an image")
62
  hex_color = sanitize_hex_color(hex_color)
63
  processed_image = remove_background_color(image, hex_color, tolerance)
64
+ return processed_image # Return only the processed image
65
  except Exception as e:
66
  gr.Warning(str(e))
67
+ return image # Return original image in case of error
68
 
69
  # Deploy using Gradio Client
70
  iface = gr.Interface(
 
72
  inputs=[
73
  gr.Image(type="numpy", label="Upload Image"),
74
  gr.Textbox(label="Hex Color to Remove", placeholder="#FFFFFF"),
75
+ gr.Slider(minimum=0, maximum=255, value=40, step=1, label="Color Tolerance"),
76
+ gr.ColorPicker(label="Pick a Color") # Color picker remains
77
  ],
78
  outputs=[
79
+ gr.Image(type="numpy", label="Processed Image") # Removed output textbox
 
80
  ],
81
+ title="Image Colour Remover",
82
  description="""
83
+ Remove a specific colour from your image with precision!
84
 
85
  ### How to Use:
86
  1. Upload an image
87
+ 2. Choose the colour to remove
88
+ 3. Adjust the colour tolerance (higher numbers will remove similair colours to hex code entered)
89
  4. See the magic happen!
90
  """,
 
91
  )
92
 
93
  iface.launch(share=True) # Launch the interface with a shareable link