not-lain commited on
Commit
521737f
β€’
1 Parent(s): 3e75999

🌘wπŸŒ–

Browse files
Files changed (2) hide show
  1. app.py +6 -5
  2. chameleon.jpg +0 -0
app.py CHANGED
@@ -5,7 +5,7 @@ import spaces
5
  from transformers import AutoModelForImageSegmentation
6
  import torch
7
  from torchvision import transforms
8
-
9
  torch.set_float32_matmul_precision(['high', 'highest'][0])
10
 
11
  birefnet = AutoModelForImageSegmentation.from_pretrained('ZhengPeng7/BiRefNet', trust_remote_code=True)
@@ -20,7 +20,7 @@ transform_image = transforms.Compose([
20
 
21
  @spaces.GPU
22
  def fn(image):
23
- im = load_img(image)
24
  im = im.convert('RGB')
25
  image_size = im.size
26
  origin = im.copy()
@@ -40,9 +40,10 @@ slider2 = ImageSlider(label="birefnet", type="pil")
40
  image = gr.Image(label="Upload an image")
41
  text = gr.Textbox(label="Paste an image URL")
42
 
43
-
44
- tab1 = gr.Interface(fn,inputs= image, outputs= slider1, api_name="image")
45
- tab2 = gr.Interface(fn,inputs= text, outputs= slider2, api_name="text")
 
46
 
47
  demo = gr.TabbedInterface([tab1,tab2],["image","text"],title="birefnet with image slider")
48
 
 
5
  from transformers import AutoModelForImageSegmentation
6
  import torch
7
  from torchvision import transforms
8
+ from PIL import Image
9
  torch.set_float32_matmul_precision(['high', 'highest'][0])
10
 
11
  birefnet = AutoModelForImageSegmentation.from_pretrained('ZhengPeng7/BiRefNet', trust_remote_code=True)
 
20
 
21
  @spaces.GPU
22
  def fn(image):
23
+ im = load_img(image,output_type="pil")
24
  im = im.convert('RGB')
25
  image_size = im.size
26
  origin = im.copy()
 
40
  image = gr.Image(label="Upload an image")
41
  text = gr.Textbox(label="Paste an image URL")
42
 
43
+ chameleon = Image.open("chameleon.jpg")
44
+ url = "https://hips.hearstapps.com/hmg-prod/images/gettyimages-1229892983-square.jpg"
45
+ tab1 = gr.Interface(fn,inputs= image, outputs= slider1,examples=[chameleon], api_name="image")
46
+ tab2 = gr.Interface(fn,inputs= text, outputs= slider2,examples=[url], api_name="text")
47
 
48
  demo = gr.TabbedInterface([tab1,tab2],["image","text"],title="birefnet with image slider")
49
 
chameleon.jpg ADDED