Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,13 +7,17 @@ import gradio as gr
|
|
| 7 |
CSV_PATH = "best_models_summary.csv"
|
| 8 |
df = pd.read_csv(CSV_PATH)
|
| 9 |
|
| 10 |
-
# ---------------- Generate Compatible Features ----------------
|
| 11 |
-
def generate_features():
|
| 12 |
-
# Match your model input size (768)
|
| 13 |
-
return np.random.rand(1, 768).astype(np.float32)
|
| 14 |
-
|
| 15 |
# ---------------- Prediction Function ----------------
|
| 16 |
-
def predict_features(dataset_type, metric_priority):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# ---------------- Select Best Model ----------------
|
| 19 |
subset = df[df['dataset'] == dataset_type]
|
|
@@ -34,9 +38,6 @@ def predict_features(dataset_type, metric_priority):
|
|
| 34 |
except Exception as e:
|
| 35 |
return f"❌ Error loading model: {e}"
|
| 36 |
|
| 37 |
-
# ---------------- Generate Features ----------------
|
| 38 |
-
features = generate_features()
|
| 39 |
-
|
| 40 |
# ---------------- Prediction ----------------
|
| 41 |
try:
|
| 42 |
pred = model.predict(features)[0]
|
|
@@ -67,15 +68,12 @@ with gr.Blocks(css="""
|
|
| 67 |
.gr-button {background-color: #ff6f61; color:white; font-weight:bold;}
|
| 68 |
""") as demo:
|
| 69 |
|
| 70 |
-
gr.Markdown("<h1>🔥 Wildfire Classification 🔥</h1>")
|
| 71 |
-
gr.Markdown("
|
| 72 |
|
| 73 |
with gr.Row():
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
label="Dataset Type"
|
| 77 |
-
)
|
| 78 |
-
|
| 79 |
metric_priority = gr.Dropdown(
|
| 80 |
choices=['accuracy','precision','recall','f1_score','best_overall'],
|
| 81 |
label="Metric Priority"
|
|
@@ -87,7 +85,7 @@ with gr.Blocks(css="""
|
|
| 87 |
|
| 88 |
predict_btn.click(
|
| 89 |
fn=predict_features,
|
| 90 |
-
inputs=[dataset_type, metric_priority],
|
| 91 |
outputs=output_text
|
| 92 |
)
|
| 93 |
|
|
|
|
| 7 |
CSV_PATH = "best_models_summary.csv"
|
| 8 |
df = pd.read_csv(CSV_PATH)
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# ---------------- Prediction Function ----------------
|
| 11 |
+
def predict_features(uploaded_file, dataset_type, metric_priority):
|
| 12 |
+
|
| 13 |
+
try:
|
| 14 |
+
features = np.load(uploaded_file) # user uploads .npy feature
|
| 15 |
+
except Exception as e:
|
| 16 |
+
return f"❌ Error loading feature file: {e}"
|
| 17 |
+
|
| 18 |
+
# Ensure correct shape
|
| 19 |
+
if len(features.shape) == 1:
|
| 20 |
+
features = features.reshape(1, -1)
|
| 21 |
|
| 22 |
# ---------------- Select Best Model ----------------
|
| 23 |
subset = df[df['dataset'] == dataset_type]
|
|
|
|
| 38 |
except Exception as e:
|
| 39 |
return f"❌ Error loading model: {e}"
|
| 40 |
|
|
|
|
|
|
|
|
|
|
| 41 |
# ---------------- Prediction ----------------
|
| 42 |
try:
|
| 43 |
pred = model.predict(features)[0]
|
|
|
|
| 68 |
.gr-button {background-color: #ff6f61; color:white; font-weight:bold;}
|
| 69 |
""") as demo:
|
| 70 |
|
| 71 |
+
gr.Markdown("<h1>🔥 Wildfire Feature Classification 🔥</h1>")
|
| 72 |
+
gr.Markdown("Upload a feature vector (.npy file) extracted using Xception.")
|
| 73 |
|
| 74 |
with gr.Row():
|
| 75 |
+
uploaded_file = gr.File(label="Upload Feature (.npy)", file_types=['.npy'])
|
| 76 |
+
dataset_type = gr.Dropdown(choices=['satellite','uav'], label="Dataset Type")
|
|
|
|
|
|
|
|
|
|
| 77 |
metric_priority = gr.Dropdown(
|
| 78 |
choices=['accuracy','precision','recall','f1_score','best_overall'],
|
| 79 |
label="Metric Priority"
|
|
|
|
| 85 |
|
| 86 |
predict_btn.click(
|
| 87 |
fn=predict_features,
|
| 88 |
+
inputs=[uploaded_file, dataset_type, metric_priority],
|
| 89 |
outputs=output_text
|
| 90 |
)
|
| 91 |
|