add segment checkbox
Browse files
app.py
CHANGED
|
@@ -25,7 +25,7 @@ def base64str_to_PILImage(base64str):
|
|
| 25 |
bytesObj = io.BytesIO(base64bytes)
|
| 26 |
return ImageOps.exif_transpose(Image.open(bytesObj))
|
| 27 |
|
| 28 |
-
def get_results(image, prompt):
|
| 29 |
threshold = 0.5
|
| 30 |
|
| 31 |
# Convert the NumPy array to PIL image
|
|
@@ -37,8 +37,12 @@ def get_results(image, prompt):
|
|
| 37 |
base64str = base64.b64encode(output.getvalue()).decode("utf-8")
|
| 38 |
|
| 39 |
# Prepare the payload (Adjust this part according to the API requirements)
|
| 40 |
-
payload = json.dumps({"base64str": base64str, "classes": prompt})
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
# Send the request to the API
|
| 43 |
response = requests.put(api_key, data=payload)
|
| 44 |
|
|
@@ -137,16 +141,18 @@ with gr.Blocks() as demo:
|
|
| 137 |
# Define the output component and add it to the layout
|
| 138 |
with gr.Row():
|
| 139 |
text_input = gr.inputs.Textbox(label="Prompt")
|
|
|
|
|
|
|
| 140 |
with gr.Row():
|
| 141 |
button = gr.Button("Run")
|
| 142 |
|
| 143 |
# Define the event listener that connects the input and output components and triggers the function
|
| 144 |
-
button.click(fn=get_results, inputs=[image_input, text_input], outputs=output, api_name="get_results")
|
| 145 |
# Add the description below the layout
|
| 146 |
gr.Examples(
|
| 147 |
fn=get_results,
|
| 148 |
examples=examples,
|
| 149 |
-
inputs=[image_input, text_input],
|
| 150 |
outputs=[output]
|
| 151 |
)
|
| 152 |
gr.Markdown(description_html)
|
|
|
|
| 25 |
bytesObj = io.BytesIO(base64bytes)
|
| 26 |
return ImageOps.exif_transpose(Image.open(bytesObj))
|
| 27 |
|
| 28 |
+
def get_results(image, prompt,segment):
|
| 29 |
threshold = 0.5
|
| 30 |
|
| 31 |
# Convert the NumPy array to PIL image
|
|
|
|
| 37 |
base64str = base64.b64encode(output.getvalue()).decode("utf-8")
|
| 38 |
|
| 39 |
# Prepare the payload (Adjust this part according to the API requirements)
|
| 40 |
+
#payload = json.dumps({"base64str": base64str, "classes": prompt})
|
| 41 |
+
payload = {
|
| 42 |
+
"base64str": base64str,
|
| 43 |
+
"classes": prompt,
|
| 44 |
+
"segment": "1" if segment else "0" # 1 if checkbox is selected, 0 if not
|
| 45 |
+
}
|
| 46 |
# Send the request to the API
|
| 47 |
response = requests.put(api_key, data=payload)
|
| 48 |
|
|
|
|
| 141 |
# Define the output component and add it to the layout
|
| 142 |
with gr.Row():
|
| 143 |
text_input = gr.inputs.Textbox(label="Prompt")
|
| 144 |
+
with gr.Row():
|
| 145 |
+
segment_checkbox = gr.inputs.Checkbox(label="Segment", default=False)
|
| 146 |
with gr.Row():
|
| 147 |
button = gr.Button("Run")
|
| 148 |
|
| 149 |
# Define the event listener that connects the input and output components and triggers the function
|
| 150 |
+
button.click(fn=get_results, inputs=[image_input, text_input, segment_checkbox], outputs=output, api_name="get_results")
|
| 151 |
# Add the description below the layout
|
| 152 |
gr.Examples(
|
| 153 |
fn=get_results,
|
| 154 |
examples=examples,
|
| 155 |
+
inputs=[image_input, text_input,segment_checkbox],
|
| 156 |
outputs=[output]
|
| 157 |
)
|
| 158 |
gr.Markdown(description_html)
|