Spaces:
Running
Running
Commit ·
864d929
1
Parent(s): fc96c37
Adicionar sincronização de inference_data
Browse files- data/inference_data.parquet +0 -3
- predict.py +11 -4
- requirements.txt +2 -1
data/inference_data.parquet
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:cdd3b6343a581a7a370de0b0835b6f34b5ad5fb2d6caf27c5a55bb29c08ccf90
|
| 3 |
-
size 41010819
|
|
|
|
|
|
|
|
|
|
|
|
predict.py
CHANGED
|
@@ -9,6 +9,7 @@ import tensorflow as tf
|
|
| 9 |
import matplotlib.pyplot as plt
|
| 10 |
import base64
|
| 11 |
from io import BytesIO
|
|
|
|
| 12 |
|
| 13 |
warnings.filterwarnings('ignore')
|
| 14 |
plt.style.use('seaborn-v0_8-darkgrid')
|
|
@@ -44,7 +45,15 @@ class DenguePredictor:
|
|
| 44 |
def load_assets(self):
|
| 45 |
print("INFO: Carregando todos os ativos da IA (modelo, scalers, dados)...")
|
| 46 |
AI_ASSETS_DIR = self.project_root / "models"
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
SCALER_DIR = AI_ASSETS_DIR / "scalers"
|
| 49 |
MODEL_PATH = AI_ASSETS_DIR / "checkpoints" / "model_checkpoint_best_city.keras"
|
| 50 |
|
|
@@ -52,9 +61,8 @@ class DenguePredictor:
|
|
| 52 |
self.scaler_dyn = joblib.load(SCALER_DIR / "scaler_dyn_global.pkl")
|
| 53 |
self.scaler_static = joblib.load(SCALER_DIR / "scaler_static_global.pkl")
|
| 54 |
self.scaler_target = joblib.load(SCALER_DIR / "scaler_target_global.pkl")
|
| 55 |
-
# O scaler de velocidade não é usado na inversão para o usuário final, mas é bom tê-lo
|
| 56 |
-
# self.scaler_velocity = joblib.load(SCALER_DIR / "scaler_velocidade_global.pkl")
|
| 57 |
|
|
|
|
| 58 |
df_master = pd.read_parquet(INFERENCE_PATH)
|
| 59 |
df_master['codigo_ibge'] = df_master['codigo_ibge'].astype(int)
|
| 60 |
df_master['date'] = pd.to_datetime(df_master['ano'].astype(str) + df_master['semana'].astype(str) + '0', format='%Y%W%w', errors='coerce')
|
|
@@ -106,7 +114,6 @@ class DenguePredictor:
|
|
| 106 |
pred_casos_scaled = predictions_scaled[0] # Primeira saída do modelo
|
| 107 |
|
| 108 |
# 5. Inverte a transformação para obter o número de casos reais
|
| 109 |
-
# ✅ CORREÇÃO: Remodela o array de 1D para 2D, como o scaler espera.
|
| 110 |
pred_casos_log = self.scaler_target.inverse_transform(pred_casos_scaled.reshape(1, -1))
|
| 111 |
pred_casos_real = np.expm1(pred_casos_log).flatten()
|
| 112 |
|
|
|
|
| 9 |
import matplotlib.pyplot as plt
|
| 10 |
import base64
|
| 11 |
from io import BytesIO
|
| 12 |
+
from huggingface_hub import hf_hub_download
|
| 13 |
|
| 14 |
warnings.filterwarnings('ignore')
|
| 15 |
plt.style.use('seaborn-v0_8-darkgrid')
|
|
|
|
| 45 |
def load_assets(self):
|
| 46 |
print("INFO: Carregando todos os ativos da IA (modelo, scalers, dados)...")
|
| 47 |
AI_ASSETS_DIR = self.project_root / "models"
|
| 48 |
+
|
| 49 |
+
# --- MUDANÇA: Baixa o arquivo do Hugging Face para o caminho local ---
|
| 50 |
+
INFERENCE_PATH = hf_hub_download(
|
| 51 |
+
repo_id='previdengue/predict_inference_data',
|
| 52 |
+
filename='inference_data.parquet',
|
| 53 |
+
repo_type='dataset',
|
| 54 |
+
token=os.environ.get('HF_TOKEN') # Autenticação com o token de acesso
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
SCALER_DIR = AI_ASSETS_DIR / "scalers"
|
| 58 |
MODEL_PATH = AI_ASSETS_DIR / "checkpoints" / "model_checkpoint_best_city.keras"
|
| 59 |
|
|
|
|
| 61 |
self.scaler_dyn = joblib.load(SCALER_DIR / "scaler_dyn_global.pkl")
|
| 62 |
self.scaler_static = joblib.load(SCALER_DIR / "scaler_static_global.pkl")
|
| 63 |
self.scaler_target = joblib.load(SCALER_DIR / "scaler_target_global.pkl")
|
|
|
|
|
|
|
| 64 |
|
| 65 |
+
# Lê os dados de inferência do arquivo baixado
|
| 66 |
df_master = pd.read_parquet(INFERENCE_PATH)
|
| 67 |
df_master['codigo_ibge'] = df_master['codigo_ibge'].astype(int)
|
| 68 |
df_master['date'] = pd.to_datetime(df_master['ano'].astype(str) + df_master['semana'].astype(str) + '0', format='%Y%W%w', errors='coerce')
|
|
|
|
| 114 |
pred_casos_scaled = predictions_scaled[0] # Primeira saída do modelo
|
| 115 |
|
| 116 |
# 5. Inverte a transformação para obter o número de casos reais
|
|
|
|
| 117 |
pred_casos_log = self.scaler_target.inverse_transform(pred_casos_scaled.reshape(1, -1))
|
| 118 |
pred_casos_real = np.expm1(pred_casos_log).flatten()
|
| 119 |
|
requirements.txt
CHANGED
|
@@ -12,4 +12,5 @@ matplotlib==3.10.3
|
|
| 12 |
tensorflow==2.20.0
|
| 13 |
epiweeks==2.3.0
|
| 14 |
scikit-learn==1.6.1
|
| 15 |
-
fastparquet
|
|
|
|
|
|
| 12 |
tensorflow==2.20.0
|
| 13 |
epiweeks==2.3.0
|
| 14 |
scikit-learn==1.6.1
|
| 15 |
+
fastparquet
|
| 16 |
+
huggingface_hub
|