File size: 2,284 Bytes
e7d70ba
 
 
 
 
 
 
 
 
363d01e
 
 
 
 
e7d70ba
 
 
 
 
 
 
 
7b1a980
 
e7d70ba
 
 
eddb0e1
e7d70ba
 
 
 
 
 
 
 
 
 
 
 
7b1a980
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e7d70ba
 
 
7b1a980
e7d70ba
 
 
7b1a980
e7d70ba
 
 
 
 
 
eddb0e1
e7d70ba
 
 
 
7b1a980
 
 
 
 
e7d70ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import gradio as gr
from pathlib import Path

# -----------------------------
# Image paths
# -----------------------------
BASE_DIR = Path(__file__).parent

OUTPUT_IMAGES = [
    BASE_DIR / "out1.png",
    BASE_DIR / "out2.png",
    BASE_DIR / "out3.png",
    BASE_DIR / "out4.png",
    BASE_DIR / "out5.png",
]


# -----------------------------
# Analyze function
# -----------------------------
def analyze_image(input_image):
    """
    The user uploads an input image.
    When Analyze is clicked, the app returns the five preloaded output images.
    """

    if input_image is None:
        raise gr.Error("Please upload an input image before clicking Analyze.")

    results = []

    for img_path in OUTPUT_IMAGES:
        if img_path.exists():
            results.append(str(img_path))
        else:
            raise gr.Error(f"Missing image file: {img_path.name}")

    return results


# -----------------------------
# Custom CSS
# -----------------------------
custom_css = """
#analyze-btn {
    background: black !important;
    color: white !important;
    border: 1px solid black !important;
}

#analyze-btn:hover {
    background: #222222 !important;
    color: white !important;
}
"""


# -----------------------------
# Gradio Interface
# -----------------------------
with gr.Blocks(title="Cell Image Analysis", css=custom_css) as demo:

    gr.Markdown(
        """
        # Cell Image Analysis Demo
        """
    )

    with gr.Row():
        with gr.Column():
            input_image = gr.Image(
                label="Upload Input Image",
                type="pil",
                height=400
            )

            analyze_button = gr.Button(
                "Analyze",
                variant="primary",
                elem_id="analyze-btn"
            )

        with gr.Column():
            output_gallery = gr.Gallery(
                label="Analysis Output Images",
                columns=2,
                rows=3,
                height="auto",
                object_fit="contain"
            )

    analyze_button.click(
        fn=analyze_image,
        inputs=input_image,
        outputs=output_gallery
    )


# -----------------------------
# Launch app
# -----------------------------
if __name__ == "__main__":
    demo.launch()