1aurent commited on
Commit
e9f434e
·
unverified ·
1 Parent(s): 2a8bb88

add gradio_imageslider

Browse files
Files changed (2) hide show
  1. app.py +14 -6
  2. requirements.txt +1 -0
app.py CHANGED
@@ -5,6 +5,7 @@ import gradio as gr
5
  import httpx
6
  from environs import Env
7
  from gradio_image_annotation import image_annotator
 
8
  from PIL import Image
9
 
10
  env = Env()
@@ -18,7 +19,10 @@ with env.prefixed("ERASER_"):
18
  auth = None if API_KEY is None else httpx.BasicAuth("hf", API_KEY)
19
 
20
 
21
- def process_bbox(prompts: dict[str, Any], request: gr.Request | None) -> Image.Image:
 
 
 
22
  assert isinstance(img := prompts["image"], Image.Image)
23
  assert isinstance(boxes := prompts["boxes"], list)
24
  assert len(boxes) == 1
@@ -40,7 +44,9 @@ def process_bbox(prompts: dict[str, Any], request: gr.Request | None) -> Image.I
40
  headers=headers,
41
  )
42
  r.raise_for_status()
43
- return Image.open(io.BytesIO(r.content))
 
 
44
 
45
 
46
  def on_change_bbox(prompts: dict[str, Any]):
@@ -51,7 +57,7 @@ def process_prompt(
51
  img: Image.Image,
52
  prompt: str,
53
  request: gr.Request | None,
54
- ) -> Image.Image:
55
  data = {"prompt": prompt}
56
  headers = {}
57
  if request: # avoid DOS - can be None despite type hint!
@@ -69,7 +75,9 @@ def process_prompt(
69
  headers=headers,
70
  )
71
  r.raise_for_status()
72
- return Image.open(io.BytesIO(r.content))
 
 
73
 
74
 
75
  def on_change_prompt(img: Image.Image | None, prompt: str | None):
@@ -125,7 +133,7 @@ with gr.Blocks() as demo:
125
  iimg = gr.Image(type="pil", label="Input")
126
  prompt = gr.Textbox(label="What should we erase?")
127
  with gr.Column():
128
- oimg = gr.Image(show_label=False, label="Output")
129
  with gr.Row():
130
  btn = gr.Button("Erase Object", interactive=False)
131
  for inp in [iimg, prompt]:
@@ -195,7 +203,7 @@ with gr.Blocks() as demo:
195
  label="Input",
196
  )
197
  with gr.Column():
198
- oimg = gr.Image(show_label=False, label="Output")
199
  with gr.Row():
200
  btn = gr.Button("Erase Object", interactive=False)
201
  annotator.change(
 
5
  import httpx
6
  from environs import Env
7
  from gradio_image_annotation import image_annotator
8
+ from gradio_imageslider import ImageSlider
9
  from PIL import Image
10
 
11
  env = Env()
 
19
  auth = None if API_KEY is None else httpx.BasicAuth("hf", API_KEY)
20
 
21
 
22
+ def process_bbox(
23
+ prompts: dict[str, Any],
24
+ request: gr.Request | None,
25
+ ) -> tuple[Image.Image, Image.Image]:
26
  assert isinstance(img := prompts["image"], Image.Image)
27
  assert isinstance(boxes := prompts["boxes"], list)
28
  assert len(boxes) == 1
 
44
  headers=headers,
45
  )
46
  r.raise_for_status()
47
+
48
+ output_image = Image.open(io.BytesIO(r.content))
49
+ return (img, output_image)
50
 
51
 
52
  def on_change_bbox(prompts: dict[str, Any]):
 
57
  img: Image.Image,
58
  prompt: str,
59
  request: gr.Request | None,
60
+ ) -> tuple[Image.Image, Image.Image]:
61
  data = {"prompt": prompt}
62
  headers = {}
63
  if request: # avoid DOS - can be None despite type hint!
 
75
  headers=headers,
76
  )
77
  r.raise_for_status()
78
+
79
+ output_image = Image.open(io.BytesIO(r.content))
80
+ return (img, output_image)
81
 
82
 
83
  def on_change_prompt(img: Image.Image | None, prompt: str | None):
 
133
  iimg = gr.Image(type="pil", label="Input")
134
  prompt = gr.Textbox(label="What should we erase?")
135
  with gr.Column():
136
+ oimg = ImageSlider(label="Output")
137
  with gr.Row():
138
  btn = gr.Button("Erase Object", interactive=False)
139
  for inp in [iimg, prompt]:
 
203
  label="Input",
204
  )
205
  with gr.Column():
206
+ oimg = ImageSlider(label="Output")
207
  with gr.Row():
208
  btn = gr.Button("Erase Object", interactive=False)
209
  annotator.change(
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  gradio_image_annotation==0.2.3
 
2
  environs>=11.0.0
3
  httpx>=0.27.0
4
  pillow>=10.4.0
 
1
  gradio_image_annotation==0.2.3
2
+ gradio_imageslider>=0.0.20
3
  environs>=11.0.0
4
  httpx>=0.27.0
5
  pillow>=10.4.0