ysharma HF staff commited on
Commit
bd9441c
1 Parent(s): 3e3fe6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -15
app.py CHANGED
@@ -9,25 +9,20 @@ import uuid
9
  client = Client("ysharma/BiRefNet_for_text_writing")
10
 
11
  def remove_background(image):
12
- # Convert NumPy array to PIL Image
13
- #image = Image.fromarray(image_array)
14
  # Save the image to a specific location
15
  filename = f"image_{uuid.uuid4()}.png" # Generates a universally unique identifier (UUID) for the filename
16
  image.save(filename)
17
-
18
  result = client.predict(images=handle_file(filename), api_name="/image")
19
  return Image.open(result[0])
20
 
21
  def superimpose(image_with_text, overlay_image):
22
- # Open both images as RGBA to handle transparency
23
- #background = image_with_text #Image.open("/content/out2.png").convert("RGBA")
24
  overlay_image = overlay_image.convert("RGBA")
25
  # Paste overlay on the background
26
  image_with_text.paste(overlay_image, (0, 0), overlay_image)
27
-
28
- # Display or save the final image
29
- #background.show()
30
- # background.save("output_image.png")
31
  return image_with_text
32
 
33
 
@@ -160,13 +155,13 @@ def create_interface():
160
  gr.Examples(
161
  examples=[
162
  [
163
- "sample.jpg", # Replace with actual example image path
164
- "SAMPLE TEXT",
165
- 400,
166
- "White",
167
- 255,
168
  50,
169
- 50
170
  ]
171
  ],
172
  inputs=[
 
9
  client = Client("ysharma/BiRefNet_for_text_writing")
10
 
11
  def remove_background(image):
 
 
12
  # Save the image to a specific location
13
  filename = f"image_{uuid.uuid4()}.png" # Generates a universally unique identifier (UUID) for the filename
14
  image.save(filename)
15
+ # Call gradio client for background removal
16
  result = client.predict(images=handle_file(filename), api_name="/image")
17
  return Image.open(result[0])
18
 
19
  def superimpose(image_with_text, overlay_image):
20
+ # Open image as RGBA to handle transparency
 
21
  overlay_image = overlay_image.convert("RGBA")
22
  # Paste overlay on the background
23
  image_with_text.paste(overlay_image, (0, 0), overlay_image)
24
+ # Save the final image
25
+ # image_with_text.save("output_image.png")
 
 
26
  return image_with_text
27
 
28
 
 
155
  gr.Examples(
156
  examples=[
157
  [
158
+ "pink_convertible.webp",
159
+ "EPIC",
160
+ 420,
161
+ "Purple",
162
+ 150,
163
  50,
164
+ 21
165
  ]
166
  ],
167
  inputs=[