Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,7 +59,7 @@ def detect_circles(frame_diff, image_center, center_tolerance, param1, param2, m
|
|
| 59 |
return None
|
| 60 |
|
| 61 |
def analyze_gif(gif_file, lower_bound, upper_bound, param1, param2, center_tolerance, morph_iterations):
|
| 62 |
-
"""Analyze a GIF for
|
| 63 |
try:
|
| 64 |
# Handle Gradio file input
|
| 65 |
gif_path = gif_file.name if hasattr(gif_file, 'name') else gif_file
|
|
@@ -105,33 +105,59 @@ def analyze_gif(gif_file, lower_bound, upper_bound, param1, param2, center_toler
|
|
| 105 |
"output_frame": frames[i + 1] # Store the frame for visualization
|
| 106 |
})
|
| 107 |
|
| 108 |
-
#
|
| 109 |
growing_circle_data = []
|
|
|
|
| 110 |
if all_circle_data:
|
| 111 |
-
|
| 112 |
-
growing_circle_data.append(all_circle_data[0])
|
| 113 |
for i in range(1, len(all_circle_data)):
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
# Generate output frames and report
|
| 119 |
results = []
|
| 120 |
-
report = "Analysis Report (as of 07
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
| 125 |
output_frame = cv2.cvtColor(c["output_frame"], cv2.COLOR_GRAY2RGB)
|
| 126 |
cv2.circle(output_frame, (c["center"][0], c["center"][1]), c["radius"], (0, 255, 0), 2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
# Convert to PIL Image for Gradio
|
| 128 |
output_frame = Image.fromarray(output_frame)
|
| 129 |
results.append(output_frame)
|
| 130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
report += f"Frame {c['frame']}: Center at {c['center']}, Radius {c['radius']} pixels\n"
|
| 132 |
report += "\nConclusion: Growing concentric circles of mid-to-light pixels detected, indicative of a potential Earth-directed CME."
|
| 133 |
else:
|
| 134 |
-
report += "
|
| 135 |
|
| 136 |
return report, results
|
| 137 |
except Exception as e:
|
|
@@ -151,10 +177,10 @@ iface = gr.Interface(
|
|
| 151 |
],
|
| 152 |
outputs=[
|
| 153 |
gr.Textbox(label="Analysis Report"),
|
| 154 |
-
gr.Gallery(label="Frames with Growing
|
| 155 |
],
|
| 156 |
title="Solar CME Detection",
|
| 157 |
-
description="Upload a GIF of solar images to detect
|
| 158 |
)
|
| 159 |
|
| 160 |
if __name__ == "__main__":
|
|
|
|
| 59 |
return None
|
| 60 |
|
| 61 |
def analyze_gif(gif_file, lower_bound, upper_bound, param1, param2, center_tolerance, morph_iterations):
|
| 62 |
+
"""Analyze a GIF for concentric circles, highlighting growing series."""
|
| 63 |
try:
|
| 64 |
# Handle Gradio file input
|
| 65 |
gif_path = gif_file.name if hasattr(gif_file, 'name') else gif_file
|
|
|
|
| 105 |
"output_frame": frames[i + 1] # Store the frame for visualization
|
| 106 |
})
|
| 107 |
|
| 108 |
+
# Find the longest series of frames where the circle is growing
|
| 109 |
growing_circle_data = []
|
| 110 |
+
current_series = []
|
| 111 |
if all_circle_data:
|
| 112 |
+
current_series.append(all_circle_data[0])
|
|
|
|
| 113 |
for i in range(1, len(all_circle_data)):
|
| 114 |
+
if all_circle_data[i]["radius"] > current_series[-1]["radius"]:
|
| 115 |
+
current_series.append(all_circle_data[i])
|
| 116 |
+
else:
|
| 117 |
+
# If the radius doesn't increase, check if the current series is the longest
|
| 118 |
+
if len(current_series) > len(growing_circle_data):
|
| 119 |
+
growing_circle_data = current_series.copy()
|
| 120 |
+
current_series = [all_circle_data[i]]
|
| 121 |
+
|
| 122 |
+
# Check the last series
|
| 123 |
+
if len(current_series) > len(growing_circle_data):
|
| 124 |
+
growing_circle_data = current_series.copy()
|
| 125 |
+
|
| 126 |
+
# Mark frames that are part of the growing series
|
| 127 |
+
growing_frames = set(c["frame"] for c in growing_circle_data)
|
| 128 |
|
| 129 |
# Generate output frames and report
|
| 130 |
results = []
|
| 131 |
+
report = "Analysis Report (as of 08:07 PM PDT, May 24, 2025):\n"
|
| 132 |
+
|
| 133 |
+
# Report all detected circles
|
| 134 |
+
if all_circle_data:
|
| 135 |
+
report += f"\nAll Frames with Detected Circles ({len(all_circle_data)} frames):\n"
|
| 136 |
+
for c in all_circle_data:
|
| 137 |
+
# Visualize the frame with detected circle (green)
|
| 138 |
output_frame = cv2.cvtColor(c["output_frame"], cv2.COLOR_GRAY2RGB)
|
| 139 |
cv2.circle(output_frame, (c["center"][0], c["center"][1]), c["radius"], (0, 255, 0), 2)
|
| 140 |
+
|
| 141 |
+
# If the frame is part of the growing series, add a red circle
|
| 142 |
+
if c["frame"] in growing_frames:
|
| 143 |
+
cv2.circle(output_frame, (c["center"][0], c["center"][1]), c["radius"] + 2, (255, 0, 0), 2)
|
| 144 |
+
|
| 145 |
# Convert to PIL Image for Gradio
|
| 146 |
output_frame = Image.fromarray(output_frame)
|
| 147 |
results.append(output_frame)
|
| 148 |
|
| 149 |
+
report += f"Frame {c['frame']}: Center at {c['center']}, Radius {c['radius']} pixels\n"
|
| 150 |
+
else:
|
| 151 |
+
report += "No circles detected.\n"
|
| 152 |
+
|
| 153 |
+
# Report the growing series
|
| 154 |
+
if growing_circle_data:
|
| 155 |
+
report += f"\nSeries of Frames with Growing Circles ({len(growing_circle_data)} frames):\n"
|
| 156 |
+
for c in growing_circle_data:
|
| 157 |
report += f"Frame {c['frame']}: Center at {c['center']}, Radius {c['radius']} pixels\n"
|
| 158 |
report += "\nConclusion: Growing concentric circles of mid-to-light pixels detected, indicative of a potential Earth-directed CME."
|
| 159 |
else:
|
| 160 |
+
report += "\nNo growing concentric circles detected. CME may not be Earth-directed."
|
| 161 |
|
| 162 |
return report, results
|
| 163 |
except Exception as e:
|
|
|
|
| 177 |
],
|
| 178 |
outputs=[
|
| 179 |
gr.Textbox(label="Analysis Report"),
|
| 180 |
+
gr.Gallery(label="Frames with Detected Circles (Green: Detected, Red: Growing Series)")
|
| 181 |
],
|
| 182 |
title="Solar CME Detection",
|
| 183 |
+
description="Upload a GIF of solar images to detect concentric circles of mid-to-light pixels. All detected circles are shown in green, and the series of growing circles (indicating an Earth-directed CME) are highlighted in red. Adjust the sliders to fine-tune detection."
|
| 184 |
)
|
| 185 |
|
| 186 |
if __name__ == "__main__":
|