mischeiwiller commited on
Commit
5cdd253
1 Parent(s): e43d011

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -18
app.py CHANGED
@@ -34,8 +34,8 @@ def sort_centroids_clockwise(centroids: np.ndarray):
34
 
35
  def infer(image_input, dst_height: str, dst_width: str):
36
  if isinstance(image_input, dict):
37
- image_in = image_input["image"]
38
- mask_in = image_input["mask"]
39
  else:
40
  image_in = image_input
41
  mask_in = np.zeros_like(image_in)
@@ -77,7 +77,7 @@ def infer(image_input, dst_height: str, dst_width: str):
77
 
78
  description = """In this space you can warp an image using perspective transform with the Kornia library as seen in [this tutorial](https://kornia.github.io/tutorials/#category=Homography).
79
  1. Upload an image or use the example provided
80
- 2. Set 4 points into the image with your cursor, which define the area to warp
81
  3. Set a desired output size (or go with the default)
82
  4. Click Submit to run the demo
83
  """
@@ -86,19 +86,38 @@ description = """In this space you can warp an image using perspective transform
86
  example_image = Image.open("bruce.png")
87
  example_image_np = np.array(example_image)
88
 
89
- inputs = [
90
- gr.Image(type="numpy", label="Input Image", tool="sketch"),
91
- gr.Textbox(label="Destination Height", value="64"),
92
- gr.Textbox(label="Destination Width", value="128"),
93
- ]
94
- outputs = gr.Plot(label="Output")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
- gr.Interface(
97
- fn=infer,
98
- inputs=inputs,
99
- outputs=outputs,
100
- title="Homography Warping",
101
- description=description,
102
- examples=[[example_image_np, "64", "128"]],
103
- cache_examples=True
104
- ).launch()
 
34
 
35
  def infer(image_input, dst_height: str, dst_width: str):
36
  if isinstance(image_input, dict):
37
+ image_in = np.array(image_input['composite'])
38
+ mask_in = np.array(image_input['layers'][0]) if image_input['layers'] else np.zeros_like(image_in)
39
  else:
40
  image_in = image_input
41
  mask_in = np.zeros_like(image_in)
 
77
 
78
  description = """In this space you can warp an image using perspective transform with the Kornia library as seen in [this tutorial](https://kornia.github.io/tutorials/#category=Homography).
79
  1. Upload an image or use the example provided
80
+ 2. Set 4 points into the image using the brush tool, which define the area to warp
81
  3. Set a desired output size (or go with the default)
82
  4. Click Submit to run the demo
83
  """
 
86
  example_image = Image.open("bruce.png")
87
  example_image_np = np.array(example_image)
88
 
89
+ with gr.Blocks() as demo:
90
+ gr.Markdown("# Homography Warping")
91
+ gr.Markdown(description)
92
+
93
+ with gr.Row():
94
+ image_input = gr.ImageEditor(
95
+ type="numpy",
96
+ label="Input Image",
97
+ brush=gr.Brush(colors=["#ff0000"], size=5),
98
+ height=400,
99
+ width=600
100
+ )
101
+ output_plot = gr.Plot(label="Output")
102
+
103
+ with gr.Row():
104
+ dst_height = gr.Textbox(label="Destination Height", value="64")
105
+ dst_width = gr.Textbox(label="Destination Width", value="128")
106
+
107
+ submit_button = gr.Button("Submit")
108
+ submit_button.click(
109
+ fn=infer,
110
+ inputs=[image_input, dst_height, dst_width],
111
+ outputs=output_plot
112
+ )
113
+
114
+ gr.Examples(
115
+ examples=[[example_image_np, "64", "128"]],
116
+ inputs=[image_input, dst_height, dst_width],
117
+ outputs=output_plot,
118
+ fn=infer,
119
+ cache_examples=True
120
+ )
121
 
122
+ if __name__ == "__main__":
123
+ demo.launch()