Spaces:
Sleeping
Sleeping
Commit
·
9e7c847
1
Parent(s):
1e01088
Update: revert -12
Browse files
app.py
CHANGED
@@ -11,7 +11,6 @@ sample_images = {
|
|
11 |
"Sample 1": os.path.join(os.getcwd(), "data/xai/sample1.jpeg"),
|
12 |
"Sample 2": os.path.join(os.getcwd(), "data/xai/sample2.jpg"),
|
13 |
}
|
14 |
-
|
15 |
def load_sample_image(sample_name):
|
16 |
image_path = sample_images.get(sample_name)
|
17 |
if image_path and os.path.exists(image_path):
|
@@ -27,6 +26,7 @@ def load_sample_image(choice):
|
|
27 |
else:
|
28 |
raise ValueError("Invalid sample selection.")
|
29 |
|
|
|
30 |
def process_image(sample_choice, uploaded_image, yolo_versions=["yolov5"]):
|
31 |
print(sample_choice, upload_image)
|
32 |
if uploaded_image is not None:
|
@@ -46,72 +46,10 @@ def process_image(sample_choice, uploaded_image, yolo_versions=["yolov5"]):
|
|
46 |
result_images.append((Image.fromarray(image), f"{yolo_version} not yet implemented."))
|
47 |
return result_images
|
48 |
|
49 |
-
with gr.Blocks() as interface:
|
50 |
-
#
|
51 |
-
gr.
|
52 |
-
<style>
|
53 |
-
body {
|
54 |
-
background-color: #FFFFFF;
|
55 |
-
color: #D3D3D3; /* Set the default text color to light grey */
|
56 |
-
margin: 0; /* Remove default body margin */
|
57 |
-
padding: 0; /* Remove default body padding */
|
58 |
-
}
|
59 |
-
.gradio-container {
|
60 |
-
color: #D3D3D3; /* Ensure Gradio components also have light grey text */
|
61 |
-
margin: 0; /* Remove default body margin */
|
62 |
-
padding: 0; /* Remove default body padding */
|
63 |
-
}
|
64 |
-
h1, h2, h3, h4, h5, h6 {
|
65 |
-
color: #FFFFFF !important; /* Force all headings, paragraphs, and labels to white */
|
66 |
-
margin: 0; /* Remove default body margin */
|
67 |
-
padding: 0; /* Remove default body padding */
|
68 |
-
}
|
69 |
-
.gr-markdown {
|
70 |
-
color: #D3D3D3 !important; /* Ensure Markdown text is white */
|
71 |
-
}
|
72 |
-
.gr-button {
|
73 |
-
background-color: #007bff; /* Optional: Change button background color */
|
74 |
-
color: #D3D3D3; /* Ensure button text is light grey */
|
75 |
-
}
|
76 |
-
.gr-button:hover {
|
77 |
-
background-color: #0056b3; /* Optional: Change button hover color */
|
78 |
-
}
|
79 |
-
</style>
|
80 |
-
""")
|
81 |
-
|
82 |
-
# with gr.Blocks() as interface:
|
83 |
-
# # Update CSS to make text light grey
|
84 |
-
# gr.HTML("""
|
85 |
-
# <style>
|
86 |
-
# body {
|
87 |
-
# background-color: black;
|
88 |
-
# color: #D3D3D3; /* Set the default text color to light grey */
|
89 |
-
# }
|
90 |
-
# .gradio-container {
|
91 |
-
# color: #D3D3D3; /* Ensure Gradio components also have light grey text */
|
92 |
-
# }
|
93 |
-
# h1, h2, h3, h4, h5, h6, p, label {
|
94 |
-
# color: #FFFFFF; /* Make all headings and labels light grey */
|
95 |
-
# }
|
96 |
-
# .gr-markdown {
|
97 |
-
# color: #FFFFFF; /* Ensure Markdown text is light grey */
|
98 |
-
# }
|
99 |
-
# .gr-button {
|
100 |
-
# background-color: #007bff; /* Optional: Change button background color */
|
101 |
-
# color: #D3D3D3; /* Ensure button text is light grey */
|
102 |
-
# }
|
103 |
-
# .gr-button:hover {
|
104 |
-
# background-color: #0056b3; /* Optional: Change button hover color */
|
105 |
-
# }
|
106 |
-
# </style>
|
107 |
-
# """)
|
108 |
-
|
109 |
-
|
110 |
-
gr.Markdown("<h1 style='color: #FFFFFF;'>XAI: Visualize Object Detection of Your Models</h1>")
|
111 |
-
gr.Markdown("<p style='color: #FFFFFF;'>Select a sample image to visualize object detection.</p>")
|
112 |
-
|
113 |
default_sample = "Sample 1"
|
114 |
-
|
115 |
with gr.Row(elem_classes="orchid-green-bg"):
|
116 |
# Left side: Sample selection and upload image
|
117 |
with gr.Column():
|
@@ -122,12 +60,11 @@ with gr.Blocks() as interface:
|
|
122 |
value=default_sample, # Set default selection
|
123 |
)
|
124 |
# Upload image below sample selection
|
125 |
-
gr.Markdown("
|
126 |
upload_image = gr.Image(
|
127 |
label="Upload an Image",
|
128 |
type="pil", # Correct type for file path compatibility
|
129 |
)
|
130 |
-
|
131 |
# Right side: Selected sample image display
|
132 |
sample_display = gr.Image(
|
133 |
value=load_sample_image(default_sample),
|
@@ -145,7 +82,6 @@ with gr.Blocks() as interface:
|
|
145 |
value=["yolov5"],
|
146 |
label="Select Model(s)",
|
147 |
)
|
148 |
-
|
149 |
result_gallery = gr.Gallery(label="Results", elem_id="gallery", rows=2, height=500)
|
150 |
|
151 |
gr.Button("Run").click(
|
@@ -154,4 +90,4 @@ with gr.Blocks() as interface:
|
|
154 |
outputs=result_gallery,
|
155 |
)
|
156 |
|
157 |
-
interface.launch(share=True)
|
|
|
11 |
"Sample 1": os.path.join(os.getcwd(), "data/xai/sample1.jpeg"),
|
12 |
"Sample 2": os.path.join(os.getcwd(), "data/xai/sample2.jpg"),
|
13 |
}
|
|
|
14 |
def load_sample_image(sample_name):
|
15 |
image_path = sample_images.get(sample_name)
|
16 |
if image_path and os.path.exists(image_path):
|
|
|
26 |
else:
|
27 |
raise ValueError("Invalid sample selection.")
|
28 |
|
29 |
+
|
30 |
def process_image(sample_choice, uploaded_image, yolo_versions=["yolov5"]):
|
31 |
print(sample_choice, upload_image)
|
32 |
if uploaded_image is not None:
|
|
|
46 |
result_images.append((Image.fromarray(image), f"{yolo_version} not yet implemented."))
|
47 |
return result_images
|
48 |
|
49 |
+
with gr.Blocks(css=".orchid-green-bg { background-color: #2f4f4f !important; padding: 20px; }") as interface:
|
50 |
+
gr.Markdown("# XAI: Visualize Object Detection of Your Models")
|
51 |
+
gr.Markdown("Select a sample image to visualize object detection.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
default_sample = "Sample 1"
|
|
|
53 |
with gr.Row(elem_classes="orchid-green-bg"):
|
54 |
# Left side: Sample selection and upload image
|
55 |
with gr.Column():
|
|
|
60 |
value=default_sample, # Set default selection
|
61 |
)
|
62 |
# Upload image below sample selection
|
63 |
+
gr.Markdown("**Or upload your own image:**")
|
64 |
upload_image = gr.Image(
|
65 |
label="Upload an Image",
|
66 |
type="pil", # Correct type for file path compatibility
|
67 |
)
|
|
|
68 |
# Right side: Selected sample image display
|
69 |
sample_display = gr.Image(
|
70 |
value=load_sample_image(default_sample),
|
|
|
82 |
value=["yolov5"],
|
83 |
label="Select Model(s)",
|
84 |
)
|
|
|
85 |
result_gallery = gr.Gallery(label="Results", elem_id="gallery", rows=2, height=500)
|
86 |
|
87 |
gr.Button("Run").click(
|
|
|
90 |
outputs=result_gallery,
|
91 |
)
|
92 |
|
93 |
+
interface.launch(share=True)
|