Saqib772 commited on
Commit
0ea5dea
Β·
verified Β·
1 Parent(s): 9bc104e

Added files for application

Browse files
Files changed (4) hide show
  1. app.py +177 -0
  2. exoplanet_model.pkl +3 -0
  3. feature_names.pkl +3 -0
  4. scaler.pkl +3 -0
app.py ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import joblib
3
+ import pandas as pd
4
+ import numpy as np
5
+
6
+ # Load the trained model and preprocessing objects
7
+ model = joblib.load('exoplanet_model.pkl')
8
+ scaler = joblib.load('scaler.pkl')
9
+ feature_names = joblib.load('feature_names.pkl')
10
+
11
+ def predict_exoplanet(period, time0bk, impact, duration, depth, snr, prad,
12
+ eqt, insol, steff, slogg, sradius):
13
+ """
14
+ Predict if the input represents an exoplanet or false positive
15
+ """
16
+ try:
17
+ # Create input dictionary
18
+ input_data = {
19
+ 'tce_period': float(period),
20
+ 'tce_time0bk': float(time0bk),
21
+ 'tce_impact': float(impact),
22
+ 'tce_duration': float(duration),
23
+ 'tce_depth': float(depth),
24
+ 'tce_model_snr': float(snr),
25
+ 'tce_prad': float(prad),
26
+ 'tce_eqt': float(eqt),
27
+ 'tce_insol': float(insol),
28
+ 'tce_steff': float(steff),
29
+ 'tce_slogg': float(slogg),
30
+ 'tce_sradius': float(sradius)
31
+ }
32
+
33
+ # Create DataFrame
34
+ df = pd.DataFrame([input_data])
35
+
36
+ # Add engineered features
37
+ df['temp_radius_ratio'] = df['tce_steff'] / (df['tce_sradius'] + 1e-6)
38
+ df['period_duration_ratio'] = df['tce_period'] / (df['tce_duration'] + 1e-6)
39
+ df['snr_depth_product'] = df['tce_model_snr'] * df['tce_depth']
40
+
41
+ # Ensure correct feature order
42
+ df = df[feature_names]
43
+
44
+ # Scale features
45
+ df_scaled = scaler.transform(df)
46
+
47
+ # Make prediction
48
+ prediction = model.predict(df_scaled)[0]
49
+
50
+ # Get probability if available
51
+ if hasattr(model, 'predict_proba'):
52
+ probabilities = model.predict_proba(df_scaled)[0]
53
+ confidence = probabilities[prediction]
54
+ prob_exoplanet = probabilities[1]
55
+ prob_false_positive = probabilities[0]
56
+ else:
57
+ confidence = None
58
+ prob_exoplanet = prediction
59
+ prob_false_positive = 1 - prediction
60
+
61
+ # Format result
62
+ result = "πŸͺ EXOPLANET DETECTED" if prediction == 1 else "❌ FALSE POSITIVE"
63
+
64
+ # Create detailed output
65
+ details = f"""
66
+ ### Prediction: {result}
67
+
68
+ **Confidence:** {confidence:.2%} if confidence else 'N/A'
69
+
70
+ **Probability Breakdown:**
71
+ - Exoplanet: {prob_exoplanet:.2%}
72
+ - False Positive: {prob_false_positive:.2%}
73
+
74
+ **Input Summary:**
75
+ - Orbital Period: {period} days
76
+ - Transit Depth: {depth} ppm
77
+ - Signal-to-Noise Ratio: {snr}
78
+ - Planet Radius: {prad} Earth radii
79
+ - Stellar Temperature: {steff} K
80
+ """
81
+
82
+ return details
83
+
84
+ except Exception as e:
85
+ return f"Error: {str(e)}\n\nPlease check your input values."
86
+
87
+ # Example datasets for quick testing
88
+ examples = [
89
+ # Confirmed exoplanet-like parameters
90
+ [3.5, 135.0, 0.3, 2.5, 800, 20.0, 2.0, 450, 100, 5800, 4.5, 1.0],
91
+ # False positive-like parameters
92
+ [50.0, 200.0, 0.9, 15.0, 50, 5.0, 15.0, 300, 5, 4500, 4.8, 0.5],
93
+ # Hot Jupiter-like
94
+ [0.8, 140.0, 0.1, 1.2, 15000, 50.0, 11.0, 1500, 5000, 6200, 4.3, 1.2],
95
+ ]
96
+
97
+ # Create Gradio interface
98
+ with gr.Blocks(title="Exoplanet Detection System", theme=gr.themes.Soft()) as demo:
99
+ gr.Markdown(
100
+ """
101
+ # 🌌 Exoplanet Detection System
102
+
103
+ This AI-powered system predicts whether a transit signal represents a genuine exoplanet
104
+ or a false positive based on Kepler space telescope data.
105
+
106
+ ### How to use:
107
+ 1. Enter the transit and stellar parameters below
108
+ 2. Click "Detect Exoplanet" to get prediction
109
+ 3. Or try example cases for quick testing
110
+ """
111
+ )
112
+
113
+ with gr.Row():
114
+ with gr.Column():
115
+ gr.Markdown("### Transit Parameters")
116
+ period = gr.Number(label="Orbital Period (days)", value=10.0,
117
+ info="Time between successive transits")
118
+ time0bk = gr.Number(label="Transit Epoch (BJD - 2454833)", value=135.0,
119
+ info="Time of first transit")
120
+ impact = gr.Slider(0, 1, value=0.5, label="Impact Parameter",
121
+ info="0 = center crossing, 1 = grazing")
122
+ duration = gr.Number(label="Transit Duration (hours)", value=3.0,
123
+ info="How long the transit lasts")
124
+ depth = gr.Number(label="Transit Depth (ppm)", value=500.0,
125
+ info="Fractional decrease in brightness")
126
+ snr = gr.Number(label="Signal-to-Noise Ratio", value=15.0,
127
+ info="Quality of the detection")
128
+
129
+ with gr.Column():
130
+ gr.Markdown("### Planet & Stellar Parameters")
131
+ prad = gr.Number(label="Planet Radius (Earth radii)", value=2.5,
132
+ info="Size relative to Earth")
133
+ eqt = gr.Number(label="Equilibrium Temperature (K)", value=400.0,
134
+ info="Estimated planet temperature")
135
+ insol = gr.Number(label="Insolation (Earth flux)", value=50.0,
136
+ info="Stellar flux received")
137
+ steff = gr.Number(label="Stellar Temperature (K)", value=5500.0,
138
+ info="Host star temperature")
139
+ slogg = gr.Slider(2, 5, value=4.5, label="Stellar Surface Gravity (log g)",
140
+ info="Indicates star type")
141
+ sradius = gr.Number(label="Stellar Radius (Solar radii)", value=1.0,
142
+ info="Size of host star")
143
+
144
+ detect_btn = gr.Button("πŸ” Detect Exoplanet", variant="primary", size="lg")
145
+
146
+ output = gr.Markdown(label="Prediction Results")
147
+
148
+ detect_btn.click(
149
+ fn=predict_exoplanet,
150
+ inputs=[period, time0bk, impact, duration, depth, snr, prad,
151
+ eqt, insol, steff, slogg, sradius],
152
+ outputs=output
153
+ )
154
+
155
+ gr.Markdown("### πŸ“‹ Example Cases")
156
+ gr.Examples(
157
+ examples=examples,
158
+ inputs=[period, time0bk, impact, duration, depth, snr, prad,
159
+ eqt, insol, steff, slogg, sradius],
160
+ label="Try these example transit signals"
161
+ )
162
+
163
+ gr.Markdown(
164
+ """
165
+ ---
166
+ **Model Information:**
167
+ - Trained on Kepler mission data
168
+ - Uses ensemble machine learning techniques
169
+ - Features: Transit timing, depth, stellar parameters, and more
170
+
171
+ **Note:** This is a demonstration tool. Real exoplanet confirmation requires
172
+ extensive follow-up observations and validation.
173
+ """
174
+ )
175
+
176
+ if __name__ == "__main__":
177
+ demo.launch(share=True)
exoplanet_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aca2cbf147a8c094739a8d81f0f7045e60d13e72d5101fc9cfed6ecad43d9d74
3
+ size 2352745
feature_names.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:de57c547dc2182d5a1e9db0520bc864614a8bd7eb46fa9123988e6bb39efbb5d
3
+ size 234
scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:618ad53cbbe70776585762d4dffdc9461372a68278424fee7f5fe07000d55806
3
+ size 1519