Spaces:
Running
on
Zero
Running
on
Zero
Add an additional tab for inference with url.
Browse files
app.py
CHANGED
@@ -107,17 +107,35 @@ for idx_example, example in enumerate(examples):
|
|
107 |
examples.append(examples[-1].copy())
|
108 |
examples[-1][1] = '512x512'
|
109 |
|
110 |
-
|
111 |
fn=predict,
|
112 |
inputs=[
|
113 |
-
'image',
|
114 |
gr.Textbox(lines=1, placeholder="Type the resolution (`WxH`) you want, e.g., `1024x1024`. Higher resolutions can be much slower for inference.", label="Resolution"),
|
115 |
gr.Radio(list(usage_to_weights_file.keys()), value='General', label="Weights", info="Choose the weights you want.")
|
116 |
],
|
117 |
-
outputs=ImageSlider(),
|
118 |
examples=examples,
|
119 |
-
|
120 |
-
description=('Upload a picture, our model will extract a highly accurate segmentation of the subject in it. :)'
|
121 |
-
'\nThe resolution used in our training was `1024x1024`, thus the suggested resolution to obtain good results!\n Ours codes can be found at https://github.com/ZhengPeng7/BiRefNet.\n We also maintain the HF model of BiRefNet at https://huggingface.co/ZhengPeng7/BiRefNet for easier access.')
|
122 |
)
|
123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
examples.append(examples[-1].copy())
|
108 |
examples[-1][1] = '512x512'
|
109 |
|
110 |
+
tab_image = gr.Interface(
|
111 |
fn=predict,
|
112 |
inputs=[
|
113 |
+
gr.Image(label='Upload an image'),
|
114 |
gr.Textbox(lines=1, placeholder="Type the resolution (`WxH`) you want, e.g., `1024x1024`. Higher resolutions can be much slower for inference.", label="Resolution"),
|
115 |
gr.Radio(list(usage_to_weights_file.keys()), value='General', label="Weights", info="Choose the weights you want.")
|
116 |
],
|
117 |
+
outputs=ImageSlider(label="BiRefNet's prediction", type="pil"),
|
118 |
examples=examples,
|
119 |
+
api_name="image"
|
|
|
|
|
120 |
)
|
121 |
+
|
122 |
+
tab_text = gr.Interface(
|
123 |
+
fn=predict,
|
124 |
+
inputs=gr.Textbox(label="Paste an image URL"),
|
125 |
+
outputs=ImageSlider(label="BiRefNet's prediction", type="pil"),
|
126 |
+
examples=["https://hips.hearstapps.com/hmg-prod/images/gettyimages-1229892983-square.jpg"],
|
127 |
+
api_name="text"
|
128 |
+
)
|
129 |
+
|
130 |
+
demo = gr.TabbedInterface(
|
131 |
+
[tab_image, tab_text],
|
132 |
+
["image", "text"],
|
133 |
+
title="BiRefNet demo for subject extraction (general / salient / camouflaged / portrait)."
|
134 |
+
description=('Upload a picture, our model will extract a highly accurate segmentation of the subject in it.\n)'
|
135 |
+
' The resolution used in our training was `1024x1024`, thus the suggested resolution to obtain good results!\n'
|
136 |
+
' Our codes can be found at https://github.com/ZhengPeng7/BiRefNet.\n'
|
137 |
+
' We also maintain the HF model of BiRefNet at https://huggingface.co/ZhengPeng7/BiRefNet for easier access.')
|
138 |
+
)
|
139 |
+
|
140 |
+
if __name__ == "__main__":
|
141 |
+
demo.launch(debug=True)
|