still same crash, use download button for dummy
Browse files
app.py
CHANGED
|
@@ -13,16 +13,17 @@ def dummy_damage_classification(img, threshold):
|
|
| 13 |
# Convert to numpy array
|
| 14 |
image_np = np.array(img)
|
| 15 |
|
| 16 |
-
#
|
| 17 |
image_pil = Image.fromarray(image_np).convert("RGB")
|
| 18 |
draw = ImageDraw.Draw(image_pil)
|
| 19 |
draw.rectangle([10, 10, 50, 50], outline="red", width=3)
|
| 20 |
image_pil.save(IMAGE_PATH)
|
| 21 |
|
| 22 |
-
#
|
| 23 |
df = pd.DataFrame({"x": [20], "y": [30], "damage_type": ["Dummy"]})
|
| 24 |
df.to_csv(CSV_PATH, index=False)
|
| 25 |
|
|
|
|
| 26 |
return image_pil, IMAGE_PATH, CSV_PATH
|
| 27 |
|
| 28 |
with gr.Blocks() as app:
|
|
@@ -32,14 +33,14 @@ with gr.Blocks() as app:
|
|
| 32 |
threshold_input = gr.Number(value=20, label="Threshold")
|
| 33 |
|
| 34 |
output_image = gr.Image(label="Classified Image")
|
| 35 |
-
|
| 36 |
-
|
| 37 |
|
| 38 |
btn = gr.Button("Run Classification")
|
| 39 |
btn.click(
|
| 40 |
dummy_damage_classification,
|
| 41 |
inputs=[image_input, threshold_input],
|
| 42 |
-
outputs=[output_image,
|
| 43 |
)
|
| 44 |
|
| 45 |
if __name__ == "__main__":
|
|
|
|
| 13 |
# Convert to numpy array
|
| 14 |
image_np = np.array(img)
|
| 15 |
|
| 16 |
+
# Draw a red square on the image
|
| 17 |
image_pil = Image.fromarray(image_np).convert("RGB")
|
| 18 |
draw = ImageDraw.Draw(image_pil)
|
| 19 |
draw.rectangle([10, 10, 50, 50], outline="red", width=3)
|
| 20 |
image_pil.save(IMAGE_PATH)
|
| 21 |
|
| 22 |
+
# Create dummy CSV file
|
| 23 |
df = pd.DataFrame({"x": [20], "y": [30], "damage_type": ["Dummy"]})
|
| 24 |
df.to_csv(CSV_PATH, index=False)
|
| 25 |
|
| 26 |
+
# Return PIL image for display, and file paths (strings) for download buttons
|
| 27 |
return image_pil, IMAGE_PATH, CSV_PATH
|
| 28 |
|
| 29 |
with gr.Blocks() as app:
|
|
|
|
| 33 |
threshold_input = gr.Number(value=20, label="Threshold")
|
| 34 |
|
| 35 |
output_image = gr.Image(label="Classified Image")
|
| 36 |
+
download_image_btn = gr.DownloadButton(label="Download Image")
|
| 37 |
+
download_csv_btn = gr.DownloadButton(label="Download CSV")
|
| 38 |
|
| 39 |
btn = gr.Button("Run Classification")
|
| 40 |
btn.click(
|
| 41 |
dummy_damage_classification,
|
| 42 |
inputs=[image_input, threshold_input],
|
| 43 |
+
outputs=[output_image, download_image_btn, download_csv_btn]
|
| 44 |
)
|
| 45 |
|
| 46 |
if __name__ == "__main__":
|