Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -92,44 +92,10 @@ def segment_image(input_image, text_input):
|
|
92 |
# Return the segmented images in descending order of similarity
|
93 |
return segmented_regions
|
94 |
|
95 |
-
|
96 |
-
# def segment_image(input_image, text_input):
|
97 |
-
# image_bytes = base64.b64decode(input_image)
|
98 |
-
# image = Image.open(BytesIO(image_bytes))
|
99 |
-
|
100 |
-
# image = cv2.cvtColor(np.array(image), cv2.COLOR_BGR2RGB)
|
101 |
-
# mask_generator = SamAutomaticMaskGenerator(sam)
|
102 |
-
# masks = mask_generator.generate(image)
|
103 |
-
|
104 |
-
# segmented_regions = [] # List to store segmented regions with similarity scores
|
105 |
-
|
106 |
-
# for i, mask_dict in enumerate(masks):
|
107 |
-
# mask_data = (mask_dict['segmentation'] * 255).astype(np.uint8)
|
108 |
-
# segmented_region = cv2.bitwise_and(image, image, mask=mask_data)
|
109 |
-
|
110 |
-
# x, y, w, h = map(int, mask_dict['bbox'])
|
111 |
-
# cropped_region = segmented_region[y:y+h, x:x+w]
|
112 |
-
|
113 |
-
# # Convert to base64 image
|
114 |
-
# _, buffer = cv2.imencode(".png", cv2.cvtColor(cropped_region, cv2.COLOR_BGR2RGB))
|
115 |
-
# segmented_image_base64 = base64.b64encode(buffer).decode()
|
116 |
-
|
117 |
-
# # Calculate similarity for the segmented image
|
118 |
-
# similarity = find_similarity(segmented_image_base64, text_input)
|
119 |
-
|
120 |
-
# # Append the segmented image and its similarity score
|
121 |
-
# segmented_regions.append({"image": segmented_image_base64, "similarity": similarity})
|
122 |
-
|
123 |
-
# # Sort the segmented images by similarity in descending order
|
124 |
-
# segmented_regions.sort(key=lambda x: x["similarity"], reverse=True)
|
125 |
-
|
126 |
-
# # Return the segmented images in descending order of similarity
|
127 |
-
# return segmented_regions
|
128 |
-
|
129 |
# Create Gradio components
|
130 |
input_image = gr.Textbox(label="Base64 Image", lines=8)
|
131 |
text_input = gr.Textbox(label="Text Input") # Use Textbox with a label
|
132 |
output_images = gr.outputs.JSON()
|
133 |
|
134 |
# Create a Gradio interface
|
135 |
-
gr.Interface(fn=segment_image, inputs=[input_image, text_input], outputs=output_images).launch()
|
|
|
92 |
# Return the segmented images in descending order of similarity
|
93 |
return segmented_regions
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
# Create Gradio components
|
96 |
input_image = gr.Textbox(label="Base64 Image", lines=8)
|
97 |
text_input = gr.Textbox(label="Text Input") # Use Textbox with a label
|
98 |
output_images = gr.outputs.JSON()
|
99 |
|
100 |
# Create a Gradio interface
|
101 |
+
gr.Interface(fn=segment_image, inputs=[input_image, text_input], outputs=output_images).launch(max_responses=6)
|