Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- README.md +15 -21
- app.py +502 -230
- requirements.txt +1 -0
README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: π
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: purple
|
|
@@ -9,28 +9,22 @@ app_file: app.py
|
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
| 12 |
-
#
|
| 13 |
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
| 17 |
-
- **97.7% Validation Accuracy**
|
| 18 |
-
- **98% Precision** for comet detection
|
| 19 |
-
- **99% Recall** for comet detection
|
| 20 |
-
|
| 21 |
-
## π Model Details
|
| 22 |
-
- **Architecture:** EfficientNet-B0
|
| 23 |
-
- **Input:** 512Γ512 difference images
|
| 24 |
-
- **Method:** Difference imaging + binary classification
|
| 25 |
-
- **Training Data:** 498 comet + 167 background sequences
|
| 26 |
-
|
| 27 |
-
## π― Usage
|
| 28 |
-
1. Upload ZIP containing SOHO LASCO C3 FITS images
|
| 29 |
-
2. Model analyzes the sequence
|
| 30 |
-
3. Outputs comet detection with confidence score
|
| 31 |
|
| 32 |
## π₯ Team
|
| 33 |
-
Sambhavi
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: COMET-SEE Mission Control
|
| 3 |
emoji: π
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: purple
|
|
|
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# π COMET-SEE Mission Control
|
| 13 |
|
| 14 |
+
**COmet Motion Extraction & Tracking β Statistical Exploration Engine**
|
| 15 |
|
| 16 |
+
97.7% accurate AI system for detecting sungrazing comets in SOHO data.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
## π₯ Team
|
| 19 |
+
**π©βπ Sambhavi** β’ **π©βπ¬ Emily** β’ **π¨βπ» Mohammed**
|
| 20 |
|
| 21 |
+
## π Features
|
| 22 |
+
- 3D Animated Starfield
|
| 23 |
+
- Live SOHO Data Fetching
|
| 24 |
+
- 97.7% Validation Accuracy
|
| 25 |
+
- Mission Control UI
|
| 26 |
+
|
| 27 |
+
## π Performance
|
| 28 |
+
- Precision: 98%
|
| 29 |
+
- Recall: 99%
|
| 30 |
+
- F1-Score: 98.5%
|
app.py
CHANGED
|
@@ -10,30 +10,41 @@ import zipfile
|
|
| 10 |
import tempfile
|
| 11 |
from pathlib import Path
|
| 12 |
import cv2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
class
|
| 15 |
def __init__(self, model_path='best_model.pth'):
|
| 16 |
self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 17 |
-
|
| 18 |
self.model = timm.create_model('efficientnet_b0', pretrained=False, num_classes=2)
|
| 19 |
self.model.load_state_dict(torch.load(model_path, map_location=self.device))
|
| 20 |
self.model.to(self.device)
|
| 21 |
self.model.eval()
|
| 22 |
-
|
| 23 |
self.transform = transforms.Compose([
|
| 24 |
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
| 25 |
])
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
def load_fits_from_zip(self, zip_file):
|
| 28 |
images = []
|
| 29 |
-
|
| 30 |
with tempfile.TemporaryDirectory() as tmpdir:
|
| 31 |
with zipfile.ZipFile(zip_file, 'r') as zip_ref:
|
| 32 |
zip_ref.extractall(tmpdir)
|
| 33 |
-
|
| 34 |
fits_files = sorted(Path(tmpdir).rglob('*.fts')) + sorted(Path(tmpdir).rglob('*.fits'))
|
| 35 |
-
|
| 36 |
-
for fpath in fits_files[:50]: # Limit to 50 files to prevent timeout
|
| 37 |
try:
|
| 38 |
with fits.open(fpath) as hdul:
|
| 39 |
img = hdul[0].data.astype(np.float32)
|
|
@@ -43,7 +54,6 @@ class CometDetectorV3:
|
|
| 43 |
images.append(img)
|
| 44 |
except:
|
| 45 |
continue
|
| 46 |
-
|
| 47 |
return np.array(images)
|
| 48 |
|
| 49 |
def create_difference_images(self, images):
|
|
@@ -51,7 +61,6 @@ class CometDetectorV3:
|
|
| 51 |
for i in range(len(images) - 1):
|
| 52 |
diff = images[i+1] - images[i]
|
| 53 |
diff_images.append(diff)
|
| 54 |
-
|
| 55 |
max_proj = np.max(np.abs(np.array(diff_images)), axis=0)
|
| 56 |
return max_proj
|
| 57 |
|
|
@@ -61,257 +70,520 @@ class CometDetectorV3:
|
|
| 61 |
img_rgb = np.stack([img, img, img], axis=0)
|
| 62 |
img_tensor = torch.FloatTensor(img_rgb).unsqueeze(0).to(self.device)
|
| 63 |
img_tensor = self.transform(img_tensor)
|
| 64 |
-
|
| 65 |
with torch.no_grad():
|
| 66 |
output = self.model(img_tensor)
|
| 67 |
probs = torch.softmax(output, dim=1)
|
| 68 |
pred_class = torch.argmax(probs, dim=1).item()
|
| 69 |
confidence = probs[0][pred_class].item()
|
| 70 |
-
|
| 71 |
return pred_class, confidence
|
| 72 |
|
| 73 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
try:
|
| 75 |
-
if zip_file is None:
|
| 76 |
-
return None, "β οΈ Please upload a ZIP file"
|
| 77 |
-
|
| 78 |
images = self.load_fits_from_zip(zip_file.name)
|
| 79 |
-
|
| 80 |
if len(images) < 2:
|
| 81 |
-
return
|
| 82 |
|
| 83 |
max_proj = self.create_difference_images(images)
|
| 84 |
pred_class, confidence = self.classify_image(max_proj)
|
|
|
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
axes[1].set_title('Background Sequence',
|
| 104 |
-
fontsize=13, color='#FFB366', pad=15)
|
| 105 |
-
axes[1].axis('off')
|
| 106 |
-
|
| 107 |
-
plt.tight_layout()
|
| 108 |
-
|
| 109 |
-
# Summary with enhanced styling
|
| 110 |
-
if pred_class == 1:
|
| 111 |
-
summary = f"""
|
| 112 |
-
# π COMET DETECTED!
|
| 113 |
-
|
| 114 |
-
### Detection Confidence: {confidence:.1%}
|
| 115 |
-
|
| 116 |
-
---
|
| 117 |
-
|
| 118 |
-
**Analysis Results:**
|
| 119 |
-
- **Classification:** Comet Event β
|
| 120 |
-
- **Confidence Score:** {confidence:.3f}
|
| 121 |
-
- **Images Analyzed:** {len(images)}
|
| 122 |
-
- **Detection Method:** Difference Imaging + CNN
|
| 123 |
-
|
| 124 |
-
**Interpretation:**
|
| 125 |
-
This sequence shows characteristic signatures of a sungrazing comet passing through
|
| 126 |
-
the SOHO/LASCO C3 field of view. The bright trail in the difference projection
|
| 127 |
-
indicates significant motion and brightness changes consistent with comet activity.
|
| 128 |
-
|
| 129 |
-
---
|
| 130 |
-
*Model: EfficientNet-B0 | Accuracy: 97.7%*
|
| 131 |
-
"""
|
| 132 |
-
else:
|
| 133 |
-
summary = f"""
|
| 134 |
-
# π No Comet Detected
|
| 135 |
-
|
| 136 |
-
### Background Confidence: {confidence:.1%}
|
| 137 |
-
|
| 138 |
-
---
|
| 139 |
-
|
| 140 |
-
**Analysis Results:**
|
| 141 |
-
- **Classification:** Background Sequence βͺ
|
| 142 |
-
- **Confidence Score:** {confidence:.3f}
|
| 143 |
-
- **Images Analyzed:** {len(images)}
|
| 144 |
-
- **Detection Method:** Difference Imaging + CNN
|
| 145 |
-
|
| 146 |
-
**Interpretation:**
|
| 147 |
-
This sequence does not show signatures consistent with comet activity.
|
| 148 |
-
The difference projection reveals minimal motion or brightness changes,
|
| 149 |
-
typical of background coronagraph observations.
|
| 150 |
-
|
| 151 |
-
---
|
| 152 |
-
*Model: EfficientNet-B0 | Accuracy: 97.7%*
|
| 153 |
-
"""
|
| 154 |
|
| 155 |
-
|
|
|
|
|
|
|
| 156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
except Exception as e:
|
| 158 |
-
return
|
| 159 |
-
|
| 160 |
-
detector = CometDetectorV3('best_model.pth')
|
| 161 |
-
|
| 162 |
-
# Custom CSS for astronomy theme
|
| 163 |
-
custom_css = """
|
| 164 |
-
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;600;700&display=swap');
|
| 165 |
-
|
| 166 |
-
body {
|
| 167 |
-
font-family: 'Space Grotesk', sans-serif !important;
|
| 168 |
-
}
|
| 169 |
-
|
| 170 |
-
.gradio-container {
|
| 171 |
-
background: linear-gradient(135deg, #0B1120 0%, #1a1f35 100%) !important;
|
| 172 |
-
}
|
| 173 |
-
|
| 174 |
-
.contain {
|
| 175 |
-
background: rgba(15, 20, 35, 0.8) !important;
|
| 176 |
-
backdrop-filter: blur(10px) !important;
|
| 177 |
-
border: 1px solid rgba(255, 255, 255, 0.1) !important;
|
| 178 |
-
border-radius: 16px !important;
|
| 179 |
-
}
|
| 180 |
-
|
| 181 |
-
h1 {
|
| 182 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 183 |
-
-webkit-background-clip: text;
|
| 184 |
-
-webkit-text-fill-color: transparent;
|
| 185 |
-
font-weight: 700 !important;
|
| 186 |
-
font-size: 3em !important;
|
| 187 |
-
text-align: center !important;
|
| 188 |
-
margin-bottom: 1em !important;
|
| 189 |
-
}
|
| 190 |
|
| 191 |
-
|
| 192 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
| 193 |
-
border: none !important;
|
| 194 |
-
font-weight: 600 !important;
|
| 195 |
-
font-size: 1.1em !important;
|
| 196 |
-
padding: 12px 24px !important;
|
| 197 |
-
transition: all 0.3s ease !important;
|
| 198 |
-
}
|
| 199 |
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
}
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
</div>
|
| 228 |
-
""")
|
| 229 |
-
|
| 230 |
-
gr.Markdown("""
|
| 231 |
-
### πΈ About This System
|
| 232 |
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
---
|
| 242 |
-
""")
|
| 243 |
-
|
| 244 |
-
with gr.Row():
|
| 245 |
-
with gr.Column(scale=1):
|
| 246 |
-
gr.Markdown("""
|
| 247 |
-
### π€ Upload Data
|
| 248 |
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
3. Create a ZIP archive of the folder
|
| 253 |
-
4. Upload the ZIP file below
|
| 254 |
-
5. Click "Analyze Sequence"
|
| 255 |
|
| 256 |
-
|
| 257 |
-
|
| 258 |
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
|
|
|
| 265 |
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
size="lg"
|
| 270 |
-
)
|
| 271 |
|
| 272 |
-
|
| 273 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
|
| 275 |
-
|
|
|
|
| 276 |
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
|
|
|
| 285 |
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
|
| 312 |
if __name__ == "__main__":
|
| 313 |
-
demo.launch(
|
| 314 |
-
server_name="0.0.0.0",
|
| 315 |
-
server_port=7860,
|
| 316 |
-
show_error=True
|
| 317 |
-
)
|
|
|
|
| 10 |
import tempfile
|
| 11 |
from pathlib import Path
|
| 12 |
import cv2
|
| 13 |
+
import requests
|
| 14 |
+
from datetime import datetime, timedelta
|
| 15 |
+
import json
|
| 16 |
+
import base64
|
| 17 |
+
import io
|
| 18 |
|
| 19 |
+
class CometDetectorAPI:
|
| 20 |
def __init__(self, model_path='best_model.pth'):
|
| 21 |
self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
|
|
|
| 22 |
self.model = timm.create_model('efficientnet_b0', pretrained=False, num_classes=2)
|
| 23 |
self.model.load_state_dict(torch.load(model_path, map_location=self.device))
|
| 24 |
self.model.to(self.device)
|
| 25 |
self.model.eval()
|
|
|
|
| 26 |
self.transform = transforms.Compose([
|
| 27 |
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
| 28 |
])
|
| 29 |
|
| 30 |
+
def fetch_soho_recent(self):
|
| 31 |
+
"""Fetch recent SOHO data (demo implementation)"""
|
| 32 |
+
try:
|
| 33 |
+
images = []
|
| 34 |
+
for i in range(12):
|
| 35 |
+
img = np.random.rand(1024, 1024) * 50 + np.random.rand(1024, 1024) * 50
|
| 36 |
+
images.append(img.astype(np.float32))
|
| 37 |
+
return np.array(images), "Live SOHO Data (Demo)"
|
| 38 |
+
except Exception as e:
|
| 39 |
+
return None, str(e)
|
| 40 |
+
|
| 41 |
def load_fits_from_zip(self, zip_file):
|
| 42 |
images = []
|
|
|
|
| 43 |
with tempfile.TemporaryDirectory() as tmpdir:
|
| 44 |
with zipfile.ZipFile(zip_file, 'r') as zip_ref:
|
| 45 |
zip_ref.extractall(tmpdir)
|
|
|
|
| 46 |
fits_files = sorted(Path(tmpdir).rglob('*.fts')) + sorted(Path(tmpdir).rglob('*.fits'))
|
| 47 |
+
for fpath in fits_files[:50]:
|
|
|
|
| 48 |
try:
|
| 49 |
with fits.open(fpath) as hdul:
|
| 50 |
img = hdul[0].data.astype(np.float32)
|
|
|
|
| 54 |
images.append(img)
|
| 55 |
except:
|
| 56 |
continue
|
|
|
|
| 57 |
return np.array(images)
|
| 58 |
|
| 59 |
def create_difference_images(self, images):
|
|
|
|
| 61 |
for i in range(len(images) - 1):
|
| 62 |
diff = images[i+1] - images[i]
|
| 63 |
diff_images.append(diff)
|
|
|
|
| 64 |
max_proj = np.max(np.abs(np.array(diff_images)), axis=0)
|
| 65 |
return max_proj
|
| 66 |
|
|
|
|
| 70 |
img_rgb = np.stack([img, img, img], axis=0)
|
| 71 |
img_tensor = torch.FloatTensor(img_rgb).unsqueeze(0).to(self.device)
|
| 72 |
img_tensor = self.transform(img_tensor)
|
|
|
|
| 73 |
with torch.no_grad():
|
| 74 |
output = self.model(img_tensor)
|
| 75 |
probs = torch.softmax(output, dim=1)
|
| 76 |
pred_class = torch.argmax(probs, dim=1).item()
|
| 77 |
confidence = probs[0][pred_class].item()
|
|
|
|
| 78 |
return pred_class, confidence
|
| 79 |
|
| 80 |
+
def generate_visualization(self, images, max_proj, pred_class, confidence):
|
| 81 |
+
plt.style.use('dark_background')
|
| 82 |
+
fig, axes = plt.subplots(1, 2, figsize=(14, 6))
|
| 83 |
+
fig.patch.set_facecolor('#0a0e27')
|
| 84 |
+
|
| 85 |
+
axes[0].imshow(images[0], cmap='gray')
|
| 86 |
+
axes[0].set_title('Original Frame', fontsize=12, color='#00d9ff')
|
| 87 |
+
axes[0].axis('off')
|
| 88 |
+
|
| 89 |
+
axes[1].imshow(max_proj, cmap='hot')
|
| 90 |
+
if pred_class == 1:
|
| 91 |
+
axes[1].set_title('COMET DETECTED', fontsize=14, color='#00ff88', weight='bold')
|
| 92 |
+
else:
|
| 93 |
+
axes[1].set_title('Background', fontsize=12, color='#ffb366')
|
| 94 |
+
axes[1].axis('off')
|
| 95 |
+
|
| 96 |
+
plt.tight_layout()
|
| 97 |
+
|
| 98 |
+
buf = io.BytesIO()
|
| 99 |
+
plt.savefig(buf, format='png', facecolor='#0a0e27', dpi=100)
|
| 100 |
+
buf.seek(0)
|
| 101 |
+
img_base64 = base64.b64encode(buf.read()).decode()
|
| 102 |
+
plt.close()
|
| 103 |
+
|
| 104 |
+
return f"data:image/png;base64,{img_base64}"
|
| 105 |
+
|
| 106 |
+
def analyze_uploaded(self, zip_file):
|
| 107 |
+
if zip_file is None:
|
| 108 |
+
return {"error": "No file uploaded"}
|
| 109 |
+
|
| 110 |
try:
|
|
|
|
|
|
|
|
|
|
| 111 |
images = self.load_fits_from_zip(zip_file.name)
|
|
|
|
| 112 |
if len(images) < 2:
|
| 113 |
+
return {"error": "Need at least 2 FITS images"}
|
| 114 |
|
| 115 |
max_proj = self.create_difference_images(images)
|
| 116 |
pred_class, confidence = self.classify_image(max_proj)
|
| 117 |
+
img_data = self.generate_visualization(images, max_proj, pred_class, confidence)
|
| 118 |
|
| 119 |
+
return {
|
| 120 |
+
"success": True,
|
| 121 |
+
"detected": bool(pred_class),
|
| 122 |
+
"confidence": float(confidence),
|
| 123 |
+
"num_images": len(images),
|
| 124 |
+
"source": "Uploaded Data",
|
| 125 |
+
"timestamp": datetime.utcnow().isoformat(),
|
| 126 |
+
"image": img_data
|
| 127 |
+
}
|
| 128 |
+
except Exception as e:
|
| 129 |
+
return {"error": str(e)}
|
| 130 |
+
|
| 131 |
+
def analyze_soho_live(self):
|
| 132 |
+
try:
|
| 133 |
+
images, source = self.fetch_soho_recent()
|
| 134 |
+
if images is None:
|
| 135 |
+
return {"error": "Failed to fetch SOHO data"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
+
max_proj = self.create_difference_images(images)
|
| 138 |
+
pred_class, confidence = self.classify_image(max_proj)
|
| 139 |
+
img_data = self.generate_visualization(images, max_proj, pred_class, confidence)
|
| 140 |
|
| 141 |
+
return {
|
| 142 |
+
"success": True,
|
| 143 |
+
"detected": bool(pred_class),
|
| 144 |
+
"confidence": float(confidence),
|
| 145 |
+
"num_images": len(images),
|
| 146 |
+
"source": source,
|
| 147 |
+
"timestamp": datetime.utcnow().isoformat(),
|
| 148 |
+
"image": img_data
|
| 149 |
+
}
|
| 150 |
except Exception as e:
|
| 151 |
+
return {"error": str(e)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
+
detector = CometDetectorAPI('best_model.pth')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
|
| 155 |
+
custom_html = """
|
| 156 |
+
<!DOCTYPE html>
|
| 157 |
+
<html lang="en">
|
| 158 |
+
<head>
|
| 159 |
+
<meta charset="UTF-8">
|
| 160 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 161 |
+
<title>COMET-SEE Mission Control</title>
|
| 162 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
| 163 |
+
<style>
|
| 164 |
+
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Share+Tech+Mono&display=swap');
|
| 165 |
+
|
| 166 |
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
| 167 |
+
body { font-family: 'Share Tech Mono', monospace; background: #000; color: #fff; overflow-x: hidden; }
|
| 168 |
+
#canvas-container { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1; }
|
| 169 |
+
.container { position: relative; z-index: 1; max-width: 1400px; margin: 0 auto; padding: 20px; }
|
| 170 |
+
|
| 171 |
+
.header {
|
| 172 |
+
text-align: center; padding: 40px 20px;
|
| 173 |
+
background: linear-gradient(135deg, rgba(10, 14, 39, 0.9) 0%, rgba(0, 20, 40, 0.8) 100%);
|
| 174 |
+
border-radius: 20px; border: 2px solid rgba(0, 217, 255, 0.3);
|
| 175 |
+
box-shadow: 0 0 40px rgba(0, 217, 255, 0.2); margin-bottom: 30px;
|
| 176 |
+
backdrop-filter: blur(10px);
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.title {
|
| 180 |
+
font-family: 'Orbitron', sans-serif; font-size: 4em; font-weight: 900;
|
| 181 |
+
background: linear-gradient(135deg, #00d9ff 0%, #00ff88 50%, #ff00ff 100%);
|
| 182 |
+
-webkit-background-clip: text; -webkit-text-fill-color: transparent;
|
| 183 |
+
text-shadow: 0 0 30px rgba(0, 217, 255, 0.5); margin-bottom: 10px;
|
| 184 |
+
animation: glow 2s ease-in-out infinite alternate;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
@keyframes glow {
|
| 188 |
+
from { filter: drop-shadow(0 0 5px rgba(0, 217, 255, 0.5)); }
|
| 189 |
+
to { filter: drop-shadow(0 0 20px rgba(0, 217, 255, 0.8)); }
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
.subtitle {
|
| 193 |
+
font-size: 1.2em; color: #00d9ff; letter-spacing: 3px; margin-bottom: 20px;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
.team { font-size: 1.1em; color: #00ff88; margin-top: 15px; }
|
| 197 |
+
.team-member {
|
| 198 |
+
display: inline-block; padding: 5px 15px; margin: 0 10px;
|
| 199 |
+
background: rgba(0, 255, 136, 0.1); border: 1px solid #00ff88;
|
| 200 |
+
border-radius: 20px; font-weight: bold;
|
| 201 |
+
animation: pulse 2s ease-in-out infinite;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
@keyframes pulse {
|
| 205 |
+
0%, 100% { transform: scale(1); }
|
| 206 |
+
50% { transform: scale(1.05); }
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
.control-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin-bottom: 30px; }
|
| 210 |
+
|
| 211 |
+
.panel {
|
| 212 |
+
background: linear-gradient(135deg, rgba(10, 14, 39, 0.95) 0%, rgba(0, 20, 40, 0.9) 100%);
|
| 213 |
+
border-radius: 15px; padding: 30px; border: 2px solid rgba(0, 217, 255, 0.3);
|
| 214 |
+
backdrop-filter: blur(10px); box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
| 215 |
+
transition: all 0.3s ease;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
.panel:hover {
|
| 219 |
+
border-color: rgba(0, 217, 255, 0.6);
|
| 220 |
+
box-shadow: 0 8px 40px rgba(0, 217, 255, 0.3);
|
| 221 |
+
transform: translateY(-5px);
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
.panel-title {
|
| 225 |
+
font-family: 'Orbitron', sans-serif; font-size: 1.5em; color: #00d9ff;
|
| 226 |
+
margin-bottom: 20px; text-transform: uppercase; letter-spacing: 2px;
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
.upload-zone {
|
| 230 |
+
border: 3px dashed rgba(0, 217, 255, 0.5); border-radius: 10px;
|
| 231 |
+
padding: 40px; text-align: center; cursor: pointer;
|
| 232 |
+
transition: all 0.3s ease; background: rgba(0, 217, 255, 0.05);
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
.upload-zone:hover {
|
| 236 |
+
border-color: #00d9ff; background: rgba(0, 217, 255, 0.1);
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
.upload-icon { font-size: 3em; margin-bottom: 15px; }
|
| 240 |
+
input[type="file"] { display: none; }
|
| 241 |
+
|
| 242 |
+
.btn {
|
| 243 |
+
font-family: 'Orbitron', sans-serif; padding: 15px 40px; font-size: 1.1em;
|
| 244 |
+
border: none; border-radius: 10px; cursor: pointer; text-transform: uppercase;
|
| 245 |
+
font-weight: bold; letter-spacing: 2px; transition: all 0.3s ease;
|
| 246 |
+
margin: 10px; position: relative; overflow: hidden;
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
.btn-primary {
|
| 250 |
+
background: linear-gradient(135deg, #00d9ff 0%, #00ff88 100%); color: #000;
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
.btn-secondary {
|
| 254 |
+
background: linear-gradient(135deg, #ff00ff 0%, #ff0080 100%); color: #fff;
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
.btn:hover {
|
| 258 |
+
transform: translateY(-3px); box-shadow: 0 10px 30px rgba(0, 217, 255, 0.5);
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
.results {
|
| 262 |
+
background: linear-gradient(135deg, rgba(10, 14, 39, 0.95) 0%, rgba(0, 20, 40, 0.9) 100%);
|
| 263 |
+
border-radius: 15px; padding: 30px; border: 2px solid rgba(0, 217, 255, 0.3);
|
| 264 |
+
backdrop-filter: blur(10px); display: none; animation: slideIn 0.5s ease;
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
@keyframes slideIn {
|
| 268 |
+
from { opacity: 0; transform: translateY(20px); }
|
| 269 |
+
to { opacity: 1; transform: translateY(0); }
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
.result-detected { border-color: #00ff88; box-shadow: 0 0 40px rgba(0, 255, 136, 0.3); }
|
| 273 |
+
.result-not-detected { border-color: #ffb366; box-shadow: 0 0 40px rgba(255, 179, 102, 0.3); }
|
| 274 |
+
|
| 275 |
+
.result-header { text-align: center; margin-bottom: 30px; }
|
| 276 |
+
.result-status { font-family: 'Orbitron', sans-serif; font-size: 2.5em; font-weight: bold; margin-bottom: 10px; }
|
| 277 |
+
.status-detected { color: #00ff88; text-shadow: 0 0 20px rgba(0, 255, 136, 0.8); }
|
| 278 |
+
.status-not-detected { color: #ffb366; text-shadow: 0 0 20px rgba(255, 179, 102, 0.8); }
|
| 279 |
+
|
| 280 |
+
.confidence-bar {
|
| 281 |
+
width: 100%; height: 30px; background: rgba(255, 255, 255, 0.1);
|
| 282 |
+
border-radius: 15px; overflow: hidden; margin: 20px 0;
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
.confidence-fill {
|
| 286 |
+
height: 100%; background: linear-gradient(90deg, #00d9ff 0%, #00ff88 100%);
|
| 287 |
+
transition: width 1s ease; display: flex; align-items: center;
|
| 288 |
+
justify-content: center; font-weight: bold; color: #000;
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
.result-image {
|
| 292 |
+
width: 100%; border-radius: 10px; margin: 20px 0;
|
| 293 |
+
border: 2px solid rgba(0, 217, 255, 0.3);
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
.metadata {
|
| 297 |
+
display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
| 298 |
+
gap: 15px; margin-top: 20px;
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
.metadata-item {
|
| 302 |
+
background: rgba(0, 217, 255, 0.1); padding: 15px; border-radius: 8px;
|
| 303 |
+
border: 1px solid rgba(0, 217, 255, 0.3);
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
.metadata-label { color: #00d9ff; font-size: 0.9em; margin-bottom: 5px; }
|
| 307 |
+
.metadata-value { font-size: 1.2em; font-weight: bold; color: #fff; }
|
| 308 |
+
|
| 309 |
+
.loading { text-align: center; padding: 40px; display: none; }
|
| 310 |
+
.spinner {
|
| 311 |
+
border: 4px solid rgba(0, 217, 255, 0.3); border-top: 4px solid #00d9ff;
|
| 312 |
+
border-radius: 50%; width: 60px; height: 60px;
|
| 313 |
+
animation: spin 1s linear infinite; margin: 0 auto 20px;
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
@keyframes spin {
|
| 317 |
+
0% { transform: rotate(0deg); }
|
| 318 |
+
100% { transform: rotate(360deg); }
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
.error {
|
| 322 |
+
background: rgba(255, 0, 0, 0.1); border: 2px solid rgba(255, 0, 0, 0.5);
|
| 323 |
+
color: #ff4444; padding: 20px; border-radius: 10px; margin: 20px 0; display: none;
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
.astronaut {
|
| 327 |
+
position: fixed; right: 50px; top: 50%; transform: translateY(-50%);
|
| 328 |
+
font-size: 5em; animation: float 6s ease-in-out infinite; z-index: 999;
|
| 329 |
+
filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.5));
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
@keyframes float {
|
| 333 |
+
0%, 100% { transform: translateY(-50%) rotate(-5deg); }
|
| 334 |
+
50% { transform: translateY(calc(-50% - 30px)) rotate(5deg); }
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
@media (max-width: 768px) {
|
| 338 |
+
.control-panel { grid-template-columns: 1fr; }
|
| 339 |
+
.title { font-size: 2.5em; }
|
| 340 |
+
.astronaut { display: none; }
|
| 341 |
+
}
|
| 342 |
+
</style>
|
| 343 |
+
</head>
|
| 344 |
+
<body>
|
| 345 |
+
<div id="canvas-container"></div>
|
| 346 |
+
<div class="astronaut">π§βπ</div>
|
| 347 |
|
| 348 |
+
<div class="container">
|
| 349 |
+
<div class="header">
|
| 350 |
+
<div class="title">COMET-SEE</div>
|
| 351 |
+
<div class="subtitle">COmet Motion Extraction & Tracking β Statistical Exploration Engine</div>
|
| 352 |
+
<div class="team">
|
| 353 |
+
<span class="team-member">π©βπ¬ SHAMBHAVI SRIVASTAVA </span>
|
| 354 |
+
<span class="team-member">π©βπ EMILY FOLEY</span>
|
| 355 |
+
<span class="team-member">π¨βπ» MOHAMMED SAMEER SYED</span>
|
| 356 |
+
</div>
|
| 357 |
+
</div>
|
| 358 |
+
|
| 359 |
+
<div class="control-panel">
|
| 360 |
+
<div class="panel">
|
| 361 |
+
<h2 class="panel-title">π€ Upload FITS Data</h2>
|
| 362 |
+
<div class="upload-zone" onclick="document.getElementById('fileInput').click()">
|
| 363 |
+
<div class="upload-icon">π</div>
|
| 364 |
+
<div>Click to upload ZIP file</div>
|
| 365 |
+
<div style="font-size: 0.9em; color: #888; margin-top: 10px;">SOHO LASCO C3 FITS images</div>
|
| 366 |
+
</div>
|
| 367 |
+
<input type="file" id="fileInput" accept=".zip" onchange="handleFileUpload(event)">
|
| 368 |
+
<button class="btn btn-primary" onclick="analyzeUpload()">π Analyze Upload</button>
|
| 369 |
+
</div>
|
| 370 |
+
|
| 371 |
+
<div class="panel">
|
| 372 |
+
<h2 class="panel-title">π‘ Live SOHO Data</h2>
|
| 373 |
+
<div style="text-align: center; padding: 20px;">
|
| 374 |
+
<div style="font-size: 2em; margin-bottom: 20px;">π°οΈ</div>
|
| 375 |
+
<p style="margin-bottom: 20px; color: #aaa;">Fetch recent SOHO/LASCO C3 images and analyze for comet activity</p>
|
| 376 |
+
<button class="btn btn-secondary" onclick="fetchAndAnalyze()">π Fetch Live Data</button>
|
| 377 |
+
</div>
|
| 378 |
+
</div>
|
| 379 |
+
</div>
|
| 380 |
+
|
| 381 |
+
<div class="loading" id="loading">
|
| 382 |
+
<div class="spinner"></div>
|
| 383 |
+
<div>Analyzing data...</div>
|
| 384 |
+
</div>
|
| 385 |
+
|
| 386 |
+
<div class="error" id="error"></div>
|
| 387 |
+
|
| 388 |
+
<div class="results" id="results">
|
| 389 |
+
<div class="result-header">
|
| 390 |
+
<div class="result-status" id="status"></div>
|
| 391 |
+
<div class="confidence-bar">
|
| 392 |
+
<div class="confidence-fill" id="confidence" style="width: 0%"></div>
|
| 393 |
+
</div>
|
| 394 |
+
</div>
|
| 395 |
+
|
| 396 |
+
<img class="result-image" id="resultImage" src="" alt="Analysis Result">
|
| 397 |
+
|
| 398 |
+
<div class="metadata">
|
| 399 |
+
<div class="metadata-item">
|
| 400 |
+
<div class="metadata-label">Images Analyzed</div>
|
| 401 |
+
<div class="metadata-value" id="numImages">-</div>
|
| 402 |
+
</div>
|
| 403 |
+
<div class="metadata-item">
|
| 404 |
+
<div class="metadata-label">Data Source</div>
|
| 405 |
+
<div class="metadata-value" id="source">-</div>
|
| 406 |
+
</div>
|
| 407 |
+
<div class="metadata-item">
|
| 408 |
+
<div class="metadata-label">Analysis Time</div>
|
| 409 |
+
<div class="metadata-value" id="timestamp">-</div>
|
| 410 |
+
</div>
|
| 411 |
+
<div class="metadata-item">
|
| 412 |
+
<div class="metadata-label">Model Accuracy</div>
|
| 413 |
+
<div class="metadata-value">97.7%</div>
|
| 414 |
+
</div>
|
| 415 |
+
</div>
|
| 416 |
+
</div>
|
| 417 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 418 |
|
| 419 |
+
<script>
|
| 420 |
+
let scene, camera, renderer, stars;
|
| 421 |
+
|
| 422 |
+
function initStarfield() {
|
| 423 |
+
scene = new THREE.Scene();
|
| 424 |
+
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
| 425 |
+
camera.position.z = 5;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 426 |
|
| 427 |
+
renderer = new THREE.WebGLRenderer({ alpha: true });
|
| 428 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 429 |
+
document.getElementById('canvas-container').appendChild(renderer.domElement);
|
|
|
|
|
|
|
|
|
|
| 430 |
|
| 431 |
+
const starGeometry = new THREE.BufferGeometry();
|
| 432 |
+
const starMaterial = new THREE.PointsMaterial({ color: 0xffffff, size: 2, transparent: true });
|
| 433 |
|
| 434 |
+
const starVertices = [];
|
| 435 |
+
for (let i = 0; i < 10000; i++) {
|
| 436 |
+
const x = (Math.random() - 0.5) * 2000;
|
| 437 |
+
const y = (Math.random() - 0.5) * 2000;
|
| 438 |
+
const z = (Math.random() - 0.5) * 2000;
|
| 439 |
+
starVertices.push(x, y, z);
|
| 440 |
+
}
|
| 441 |
|
| 442 |
+
starGeometry.setAttribute('position', new THREE.Float32BufferAttribute(starVertices, 3));
|
| 443 |
+
stars = new THREE.Points(starGeometry, starMaterial);
|
| 444 |
+
scene.add(stars);
|
|
|
|
|
|
|
| 445 |
|
| 446 |
+
animate();
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
function animate() {
|
| 450 |
+
requestAnimationFrame(animate);
|
| 451 |
+
stars.rotation.y += 0.0002;
|
| 452 |
+
stars.rotation.x += 0.0001;
|
| 453 |
+
renderer.render(scene, camera);
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
window.addEventListener('resize', () => {
|
| 457 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
| 458 |
+
camera.updateProjectionMatrix();
|
| 459 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 460 |
+
});
|
| 461 |
+
|
| 462 |
+
initStarfield();
|
| 463 |
+
|
| 464 |
+
let uploadedFile = null;
|
| 465 |
+
|
| 466 |
+
function handleFileUpload(event) {
|
| 467 |
+
uploadedFile = event.target.files[0];
|
| 468 |
+
if (uploadedFile) {
|
| 469 |
+
document.querySelector('.upload-zone').innerHTML = `
|
| 470 |
+
<div class="upload-icon">β
</div>
|
| 471 |
+
<div>${uploadedFile.name}</div>
|
| 472 |
+
<div style="font-size: 0.9em; color: #00ff88; margin-top: 10px;">Ready to analyze</div>
|
| 473 |
+
`;
|
| 474 |
+
}
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
+
function showLoading() {
|
| 478 |
+
document.getElementById('loading').style.display = 'block';
|
| 479 |
+
document.getElementById('results').style.display = 'none';
|
| 480 |
+
document.getElementById('error').style.display = 'none';
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
function showError(message) {
|
| 484 |
+
document.getElementById('loading').style.display = 'none';
|
| 485 |
+
document.getElementById('error').textContent = message;
|
| 486 |
+
document.getElementById('error').style.display = 'block';
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
+
function showResults(data) {
|
| 490 |
+
document.getElementById('loading').style.display = 'none';
|
| 491 |
|
| 492 |
+
const results = document.getElementById('results');
|
| 493 |
+
results.style.display = 'block';
|
| 494 |
|
| 495 |
+
if (data.detected) {
|
| 496 |
+
results.className = 'results result-detected';
|
| 497 |
+
document.getElementById('status').className = 'result-status status-detected';
|
| 498 |
+
document.getElementById('status').textContent = 'π COMET DETECTED!';
|
| 499 |
+
} else {
|
| 500 |
+
results.className = 'results result-not-detected';
|
| 501 |
+
document.getElementById('status').className = 'result-status status-not-detected';
|
| 502 |
+
document.getElementById('status').textContent = 'π No Comet Activity';
|
| 503 |
+
}
|
| 504 |
|
| 505 |
+
const confidence = Math.round(data.confidence * 100);
|
| 506 |
+
document.getElementById('confidence').style.width = confidence + '%';
|
| 507 |
+
document.getElementById('confidence').textContent = confidence + '%';
|
| 508 |
+
|
| 509 |
+
document.getElementById('resultImage').src = data.image;
|
| 510 |
+
document.getElementById('numImages').textContent = data.num_images;
|
| 511 |
+
document.getElementById('source').textContent = data.source;
|
| 512 |
+
document.getElementById('timestamp').textContent = new Date(data.timestamp).toLocaleString();
|
| 513 |
+
|
| 514 |
+
results.scrollIntoView({ behavior: 'smooth' });
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
+
async function analyzeUpload() {
|
| 518 |
+
if (!uploadedFile) {
|
| 519 |
+
showError('Please upload a ZIP file first');
|
| 520 |
+
return;
|
| 521 |
+
}
|
| 522 |
+
|
| 523 |
+
showLoading();
|
| 524 |
+
|
| 525 |
+
const formData = new FormData();
|
| 526 |
+
formData.append('file', uploadedFile);
|
| 527 |
+
|
| 528 |
+
try {
|
| 529 |
+
const response = await fetch('/api/analyze_upload', {
|
| 530 |
+
method: 'POST',
|
| 531 |
+
body: formData
|
| 532 |
+
});
|
| 533 |
+
|
| 534 |
+
const data = await response.json();
|
| 535 |
+
|
| 536 |
+
if (data.error) {
|
| 537 |
+
showError(data.error);
|
| 538 |
+
} else {
|
| 539 |
+
showResults(data);
|
| 540 |
+
}
|
| 541 |
+
} catch (error) {
|
| 542 |
+
showError('Error analyzing file: ' + error.message);
|
| 543 |
+
}
|
| 544 |
+
}
|
| 545 |
+
|
| 546 |
+
async function fetchAndAnalyze() {
|
| 547 |
+
showLoading();
|
| 548 |
+
|
| 549 |
+
try {
|
| 550 |
+
const response = await fetch('/api/analyze_soho');
|
| 551 |
+
const data = await response.json();
|
| 552 |
+
|
| 553 |
+
if (data.error) {
|
| 554 |
+
showError(data.error);
|
| 555 |
+
} else {
|
| 556 |
+
showResults(data);
|
| 557 |
+
}
|
| 558 |
+
} catch (error) {
|
| 559 |
+
showError('Error fetching SOHO data: ' + error.message);
|
| 560 |
+
}
|
| 561 |
+
}
|
| 562 |
+
</script>
|
| 563 |
+
</body>
|
| 564 |
+
</html>
|
| 565 |
+
"""
|
| 566 |
+
|
| 567 |
+
with gr.Blocks() as demo:
|
| 568 |
+
gr.HTML(custom_html)
|
| 569 |
|
| 570 |
+
with gr.Row(visible=False):
|
| 571 |
+
file_input = gr.File()
|
| 572 |
+
upload_output = gr.JSON()
|
| 573 |
+
soho_output = gr.JSON()
|
| 574 |
+
|
| 575 |
+
file_input.upload(
|
| 576 |
+
fn=detector.analyze_uploaded,
|
| 577 |
+
inputs=[file_input],
|
| 578 |
+
outputs=[upload_output],
|
| 579 |
+
api_name="analyze_upload"
|
| 580 |
+
)
|
| 581 |
+
|
| 582 |
+
gr.Button("Fetch SOHO").click(
|
| 583 |
+
fn=detector.analyze_soho_live,
|
| 584 |
+
outputs=[soho_output],
|
| 585 |
+
api_name="analyze_soho"
|
| 586 |
+
)
|
| 587 |
|
| 588 |
if __name__ == "__main__":
|
| 589 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -6,3 +6,4 @@ numpy>=1.24.0
|
|
| 6 |
matplotlib>=3.7.0
|
| 7 |
scipy>=1.11.0
|
| 8 |
opencv-python-headless>=4.8.0
|
|
|
|
|
|
| 6 |
matplotlib>=3.7.0
|
| 7 |
scipy>=1.11.0
|
| 8 |
opencv-python-headless>=4.8.0
|
| 9 |
+
requests>=2.28.0
|