Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,15 +8,22 @@ model = joblib.load("modelo_noshows.joblib")
|
|
| 8 |
|
| 9 |
def predecir_excel(file):
|
| 10 |
try:
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
pred = model.predict(df)
|
| 13 |
df["predicción"] = ["inasistencia" if p == 0 else "asistencia" for p in pred]
|
| 14 |
|
|
|
|
| 15 |
output = io.BytesIO()
|
| 16 |
with pd.ExcelWriter(output, engine="openpyxl") as writer:
|
| 17 |
df.to_excel(writer, index=False)
|
| 18 |
output.seek(0)
|
| 19 |
-
return output, "✅ Predicción completada"
|
| 20 |
except Exception as e:
|
| 21 |
return None, f"❌ Error: {e}"
|
| 22 |
|
|
|
|
| 8 |
|
| 9 |
def predecir_excel(file):
|
| 10 |
try:
|
| 11 |
+
if file is None:
|
| 12 |
+
return None, "⚠️ No se recibió ningún archivo."
|
| 13 |
+
|
| 14 |
+
# Gradio puede pasar una ruta como string o un objeto
|
| 15 |
+
file_path = file.name if hasattr(file, "name") else file
|
| 16 |
+
|
| 17 |
+
df = pd.read_excel(file_path)
|
| 18 |
pred = model.predict(df)
|
| 19 |
df["predicción"] = ["inasistencia" if p == 0 else "asistencia" for p in pred]
|
| 20 |
|
| 21 |
+
# Guardar en memoria
|
| 22 |
output = io.BytesIO()
|
| 23 |
with pd.ExcelWriter(output, engine="openpyxl") as writer:
|
| 24 |
df.to_excel(writer, index=False)
|
| 25 |
output.seek(0)
|
| 26 |
+
return output, "✅ Predicción completada correctamente"
|
| 27 |
except Exception as e:
|
| 28 |
return None, f"❌ Error: {e}"
|
| 29 |
|