Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ from PIL import Image
|
|
| 6 |
from tensorflow.keras.models import load_model
|
| 7 |
|
| 8 |
# ---------------- Load CSV ----------------
|
| 9 |
-
CSV_PATH =
|
| 10 |
df = pd.read_csv(CSV_PATH)
|
| 11 |
|
| 12 |
# ---------------- Streamlit Page Config ----------------
|
|
@@ -37,6 +37,10 @@ h1 {
|
|
| 37 |
.stMarkdown p {
|
| 38 |
font-size:16px;
|
| 39 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
</style>
|
| 41 |
""", unsafe_allow_html=True)
|
| 42 |
|
|
@@ -59,16 +63,18 @@ with col2:
|
|
| 59 |
if uploaded_file:
|
| 60 |
img = Image.open(uploaded_file).convert('RGB')
|
| 61 |
st.image(img, caption='Uploaded Image', use_container_width=True)
|
| 62 |
-
|
| 63 |
# ---------------- Select Model ----------------
|
| 64 |
subset = df[df['dataset']==dataset_type]
|
|
|
|
| 65 |
if metric_priority != "best_overall":
|
| 66 |
subset = subset[subset['metric']==metric_priority]
|
| 67 |
else:
|
|
|
|
| 68 |
subset = subset.loc[subset['f1_score'].idxmax():subset['f1_score'].idxmax()+1]
|
| 69 |
|
| 70 |
model_row = subset.iloc[0]
|
| 71 |
-
model_path =
|
| 72 |
model_type = model_row['model_type']
|
| 73 |
|
| 74 |
st.markdown(f"### Using Model: **{model_row['model_name']}** ({model_type})")
|
|
@@ -105,10 +111,13 @@ if uploaded_file:
|
|
| 105 |
# ---------------- Display Results ----------------
|
| 106 |
st.markdown("---")
|
| 107 |
st.markdown("## Prediction Result")
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
# Optional style enhancements
|
| 113 |
st.markdown("<hr style='border:2px solid #ff6f61'>", unsafe_allow_html=True)
|
| 114 |
-
st.balloons()
|
|
|
|
| 6 |
from tensorflow.keras.models import load_model
|
| 7 |
|
| 8 |
# ---------------- Load CSV ----------------
|
| 9 |
+
CSV_PATH = "best_models_summary.csv" # Must be in the same folder
|
| 10 |
df = pd.read_csv(CSV_PATH)
|
| 11 |
|
| 12 |
# ---------------- Streamlit Page Config ----------------
|
|
|
|
| 37 |
.stMarkdown p {
|
| 38 |
font-size:16px;
|
| 39 |
}
|
| 40 |
+
.stImage>div>div>img {
|
| 41 |
+
border: 2px solid #ff6f61;
|
| 42 |
+
border-radius: 10px;
|
| 43 |
+
}
|
| 44 |
</style>
|
| 45 |
""", unsafe_allow_html=True)
|
| 46 |
|
|
|
|
| 63 |
if uploaded_file:
|
| 64 |
img = Image.open(uploaded_file).convert('RGB')
|
| 65 |
st.image(img, caption='Uploaded Image', use_container_width=True)
|
| 66 |
+
|
| 67 |
# ---------------- Select Model ----------------
|
| 68 |
subset = df[df['dataset']==dataset_type]
|
| 69 |
+
|
| 70 |
if metric_priority != "best_overall":
|
| 71 |
subset = subset[subset['metric']==metric_priority]
|
| 72 |
else:
|
| 73 |
+
# Best overall: max f1_score
|
| 74 |
subset = subset.loc[subset['f1_score'].idxmax():subset['f1_score'].idxmax()+1]
|
| 75 |
|
| 76 |
model_row = subset.iloc[0]
|
| 77 |
+
model_path = model_row['model_path']
|
| 78 |
model_type = model_row['model_type']
|
| 79 |
|
| 80 |
st.markdown(f"### Using Model: **{model_row['model_name']}** ({model_type})")
|
|
|
|
| 111 |
# ---------------- Display Results ----------------
|
| 112 |
st.markdown("---")
|
| 113 |
st.markdown("## Prediction Result")
|
| 114 |
+
if pred is not None:
|
| 115 |
+
st.success(f"Predicted Class: **{pred}** (class index for now)")
|
| 116 |
+
st.info(f"Metric Priority: **{metric_priority}**")
|
| 117 |
+
st.write(f"Model Accuracy: {model_row['accuracy']:.4f} | Precision: {model_row['precision']:.4f} | Recall: {model_row['recall']:.4f} | F1 Score: {model_row['f1_score']:.4f}")
|
| 118 |
+
else:
|
| 119 |
+
st.warning("Prediction could not be made. Check model compatibility.")
|
| 120 |
|
| 121 |
# Optional style enhancements
|
| 122 |
st.markdown("<hr style='border:2px solid #ff6f61'>", unsafe_allow_html=True)
|
| 123 |
+
st.balloons()
|