Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -62,51 +62,6 @@ async def health():
|
|
| 62 |
"service": "NASA SpaceApp API"
|
| 63 |
}
|
| 64 |
|
| 65 |
-
@app.get("/debug/files")
|
| 66 |
-
async def debug_files():
|
| 67 |
-
"""Endpoint de debug para listar archivos disponibles"""
|
| 68 |
-
current_dir = os.getcwd()
|
| 69 |
-
files_info = {
|
| 70 |
-
"current_directory": current_dir,
|
| 71 |
-
"files_in_root": [],
|
| 72 |
-
"directories": [],
|
| 73 |
-
"csv_files_found": []
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
try:
|
| 77 |
-
# Listar contenido del directorio actual
|
| 78 |
-
for item in os.listdir(current_dir):
|
| 79 |
-
item_path = os.path.join(current_dir, item)
|
| 80 |
-
if os.path.isfile(item_path):
|
| 81 |
-
files_info["files_in_root"].append(item)
|
| 82 |
-
elif os.path.isdir(item_path):
|
| 83 |
-
files_info["directories"].append(item)
|
| 84 |
-
|
| 85 |
-
# Buscar archivos CSV recursivamente
|
| 86 |
-
for root, dirs, files in os.walk(current_dir):
|
| 87 |
-
for file in files:
|
| 88 |
-
if file.endswith('.csv'):
|
| 89 |
-
full_path = os.path.join(root, file)
|
| 90 |
-
relative_path = os.path.relpath(full_path, current_dir)
|
| 91 |
-
files_info["csv_files_found"].append({
|
| 92 |
-
"filename": file,
|
| 93 |
-
"relative_path": relative_path,
|
| 94 |
-
"full_path": full_path,
|
| 95 |
-
"size_mb": round(os.path.getsize(full_path) / (1024*1024), 2)
|
| 96 |
-
})
|
| 97 |
-
|
| 98 |
-
# Verificar si la carpeta NASA_datasets existe
|
| 99 |
-
nasa_dir = os.path.join(current_dir, "NASA_datasets")
|
| 100 |
-
files_info["nasa_datasets_exists"] = os.path.exists(nasa_dir)
|
| 101 |
-
|
| 102 |
-
if files_info["nasa_datasets_exists"]:
|
| 103 |
-
files_info["nasa_datasets_files"] = os.listdir(nasa_dir)
|
| 104 |
-
|
| 105 |
-
except Exception as e:
|
| 106 |
-
files_info["error"] = str(e)
|
| 107 |
-
|
| 108 |
-
return files_info
|
| 109 |
-
|
| 110 |
@app.post("/predict", response_model=PredictResponse)
|
| 111 |
def predict(
|
| 112 |
req: PredictRequest,
|
|
@@ -160,47 +115,9 @@ def predict(
|
|
| 160 |
def load_csv_dataset(filename: str) -> pd.DataFrame:
|
| 161 |
"""Carga un CSV de NASA con manejo de comentarios y errores"""
|
| 162 |
try:
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
filename, # Directamente en el directorio raíz
|
| 167 |
-
os.path.join(".", filename), # Explícitamente en directorio actual
|
| 168 |
-
os.path.join(os.getcwd(), "NASA_datasets", filename), # Ruta absoluta
|
| 169 |
-
os.path.join(os.getcwd(), filename), # Ruta absoluta directa
|
| 170 |
-
]
|
| 171 |
-
|
| 172 |
-
# Intentar cada ruta hasta que una funcione
|
| 173 |
-
for filepath in possible_paths:
|
| 174 |
-
if os.path.exists(filepath):
|
| 175 |
-
print(f"Loading dataset from: {filepath}")
|
| 176 |
-
df = pd.read_csv(filepath, comment='#')
|
| 177 |
-
return df
|
| 178 |
-
|
| 179 |
-
# Si ninguna ruta funciona, listar contenido del directorio para debug
|
| 180 |
-
current_dir = os.getcwd()
|
| 181 |
-
print(f"Current directory: {current_dir}")
|
| 182 |
-
print(f"Files in current directory: {os.listdir(current_dir)}")
|
| 183 |
-
|
| 184 |
-
# Buscar archivos CSV recursivamente
|
| 185 |
-
csv_files = []
|
| 186 |
-
for root, dirs, files in os.walk(current_dir):
|
| 187 |
-
for file in files:
|
| 188 |
-
if file.endswith('.csv'):
|
| 189 |
-
csv_files.append(os.path.join(root, file))
|
| 190 |
-
|
| 191 |
-
print(f"CSV files found: {csv_files}")
|
| 192 |
-
|
| 193 |
-
# Intentar encontrar el archivo por nombre
|
| 194 |
-
for csv_path in csv_files:
|
| 195 |
-
if filename in csv_path:
|
| 196 |
-
print(f"Found matching file: {csv_path}")
|
| 197 |
-
df = pd.read_csv(csv_path, comment='#')
|
| 198 |
-
return df
|
| 199 |
-
|
| 200 |
-
raise FileNotFoundError(f"Dataset {filename} not found in any location. Searched paths: {possible_paths}")
|
| 201 |
-
|
| 202 |
-
except FileNotFoundError as e:
|
| 203 |
-
raise HTTPException(500, f"Error loading dataset {filename}: {str(e)}")
|
| 204 |
except Exception as e:
|
| 205 |
raise HTTPException(500, f"Error loading dataset {filename}: {str(e)}")
|
| 206 |
|
|
|
|
| 62 |
"service": "NASA SpaceApp API"
|
| 63 |
}
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
@app.post("/predict", response_model=PredictResponse)
|
| 66 |
def predict(
|
| 67 |
req: PredictRequest,
|
|
|
|
| 115 |
def load_csv_dataset(filename: str) -> pd.DataFrame:
|
| 116 |
"""Carga un CSV de NASA con manejo de comentarios y errores"""
|
| 117 |
try:
|
| 118 |
+
filepath = os.path.join("NASA_datasets", filename)
|
| 119 |
+
df = pd.read_csv(filepath, comment='#')
|
| 120 |
+
return df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
except Exception as e:
|
| 122 |
raise HTTPException(500, f"Error loading dataset {filename}: {str(e)}")
|
| 123 |
|