less miimal dummy example
Browse files
app.py
CHANGED
|
@@ -1,13 +1,46 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
with gr.Blocks() as app:
|
| 7 |
-
|
| 8 |
-
btn = gr.Button("Go")
|
| 9 |
-
btn.click(fn=f, inputs=inp, outputs=gr.Textbox(label="Out"))
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from PIL import Image, ImageDraw
|
| 5 |
|
| 6 |
+
IMAGE_PATH = "output_image.png"
|
| 7 |
+
CSV_PATH = "damage_list.csv"
|
| 8 |
+
|
| 9 |
+
def dummy_damage_classification(img, threshold):
|
| 10 |
+
if img is None:
|
| 11 |
+
return None, None, None
|
| 12 |
+
|
| 13 |
+
# Convert to numpy array
|
| 14 |
+
image_np = np.array(img)
|
| 15 |
+
|
| 16 |
+
# Dummy: 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 |
+
# Dummy CSV content
|
| 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:
|
| 29 |
+
gr.Markdown("# Minimal Damage Classifier Demo")
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
image_input = gr.Image(label="Upload SEM Image")
|
| 32 |
+
threshold_input = gr.Number(value=20, label="Threshold")
|
| 33 |
+
|
| 34 |
+
output_image = gr.Image(label="Classified Image")
|
| 35 |
+
download_image = gr.File(label="Download Image")
|
| 36 |
+
download_csv = gr.File(label="Download CSV")
|
| 37 |
|
| 38 |
+
btn = gr.Button("Run Classification")
|
| 39 |
+
btn.click(
|
| 40 |
+
dummy_damage_classification,
|
| 41 |
+
inputs=[image_input, threshold_input],
|
| 42 |
+
outputs=[output_image, download_image, download_csv]
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
app.launch()
|