Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,7 +17,7 @@ def extract_frames(gif_path):
|
|
| 17 |
img.seek(img.tell() + 1)
|
| 18 |
except EOFError:
|
| 19 |
break
|
| 20 |
-
return frames
|
| 21 |
except Exception as e:
|
| 22 |
return None, f"Error loading GIF: {str(e)}"
|
| 23 |
|
|
@@ -42,17 +42,16 @@ def detect_circles(frame_diff, min_radius=20, max_radius=200):
|
|
| 42 |
def analyze_gif(gif_file):
|
| 43 |
"""Analyze a GIF for growing concentric circles."""
|
| 44 |
try:
|
| 45 |
-
#
|
| 46 |
-
|
| 47 |
-
f.write(gif_file.read())
|
| 48 |
|
| 49 |
# Extract frames
|
| 50 |
-
frames, error = extract_frames(
|
| 51 |
if error:
|
| 52 |
-
return error
|
| 53 |
|
| 54 |
if len(frames) < 2:
|
| 55 |
-
return "GIF must have at least 2 frames for analysis."
|
| 56 |
|
| 57 |
# Initialize results
|
| 58 |
results = []
|
|
@@ -82,7 +81,7 @@ def analyze_gif(gif_file):
|
|
| 82 |
"radius": r
|
| 83 |
})
|
| 84 |
|
| 85 |
-
#
|
| 86 |
output_frame = cv2.cvtColor(frames[i + 1], cv2.COLOR_GRAY2RGB)
|
| 87 |
if circles is not None:
|
| 88 |
for (x, y, r) in circles:
|
|
@@ -99,12 +98,12 @@ def analyze_gif(gif_file):
|
|
| 99 |
frames_with_circles = [c["frame"] for c in circle_data]
|
| 100 |
|
| 101 |
# Check if radii are increasing over frames
|
| 102 |
-
is_growing = all(radii[i] < radii[i + 1] for i in range(len(radii) - 1))
|
| 103 |
center_consistent = all(
|
| 104 |
abs(centers[i][0] - centers[0][0]) < 20 and
|
| 105 |
abs(centers[i][1] - centers[0][1]) < 20
|
| 106 |
for i in range(1, len(centers))
|
| 107 |
-
)
|
| 108 |
|
| 109 |
report += f"Detected {len(circle_data)} circles across frames.\n"
|
| 110 |
for c in circle_data:
|
|
@@ -123,7 +122,7 @@ def analyze_gif(gif_file):
|
|
| 123 |
# Gradio interface
|
| 124 |
iface = gr.Interface(
|
| 125 |
fn=analyze_gif,
|
| 126 |
-
inputs=gr.File(label="Upload Solar GIF"),
|
| 127 |
outputs=[
|
| 128 |
gr.Textbox(label="Analysis Report"),
|
| 129 |
gr.Gallery(label="Frames with Detected Circles")
|
|
|
|
| 17 |
img.seek(img.tell() + 1)
|
| 18 |
except EOFError:
|
| 19 |
break
|
| 20 |
+
return frames, None
|
| 21 |
except Exception as e:
|
| 22 |
return None, f"Error loading GIF: {str(e)}"
|
| 23 |
|
|
|
|
| 42 |
def analyze_gif(gif_file):
|
| 43 |
"""Analyze a GIF for growing concentric circles."""
|
| 44 |
try:
|
| 45 |
+
# For Gradio, gif_file is a NamedString object with a 'name' attribute
|
| 46 |
+
gif_path = gif_file.name if hasattr(gif_file, 'name') else gif_file
|
|
|
|
| 47 |
|
| 48 |
# Extract frames
|
| 49 |
+
frames, error = extract_frames(gif_path)
|
| 50 |
if error:
|
| 51 |
+
return error, []
|
| 52 |
|
| 53 |
if len(frames) < 2:
|
| 54 |
+
return "GIF must have at least 2 frames for analysis.", []
|
| 55 |
|
| 56 |
# Initialize results
|
| 57 |
results = []
|
|
|
|
| 81 |
"radius": r
|
| 82 |
})
|
| 83 |
|
| 84 |
+
# Save frame with detected circles for visualization
|
| 85 |
output_frame = cv2.cvtColor(frames[i + 1], cv2.COLOR_GRAY2RGB)
|
| 86 |
if circles is not None:
|
| 87 |
for (x, y, r) in circles:
|
|
|
|
| 98 |
frames_with_circles = [c["frame"] for c in circle_data]
|
| 99 |
|
| 100 |
# Check if radii are increasing over frames
|
| 101 |
+
is_growing = all(radii[i] < radii[i + 1] for i in range(len(radii) - 1)) if len(radii) > 1 else False
|
| 102 |
center_consistent = all(
|
| 103 |
abs(centers[i][0] - centers[0][0]) < 20 and
|
| 104 |
abs(centers[i][1] - centers[0][1]) < 20
|
| 105 |
for i in range(1, len(centers))
|
| 106 |
+
) if len(centers) > 1 else False
|
| 107 |
|
| 108 |
report += f"Detected {len(circle_data)} circles across frames.\n"
|
| 109 |
for c in circle_data:
|
|
|
|
| 122 |
# Gradio interface
|
| 123 |
iface = gr.Interface(
|
| 124 |
fn=analyze_gif,
|
| 125 |
+
inputs=gr.File(label="Upload Solar GIF", file_types=[".gif"]),
|
| 126 |
outputs=[
|
| 127 |
gr.Textbox(label="Analysis Report"),
|
| 128 |
gr.Gallery(label="Frames with Detected Circles")
|