Created
March 26, 2026 06:51
-
-
Save aijadugar/caad8db6a164909e63b4d8404ff0b67e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| =======================================================Upload script | |
| pip install huggingface_hub | |
| from huggingface_hub import HfApi, login | |
| login(token="YOUR_HF_TOKEN") | |
| HF_REPO = "aijadugar/tb-risk-model" | |
| api = HfApi() | |
| api.create_repo(repo_id=HF_REPO, repo_type="model", exist_ok=True) | |
| api.upload_file( | |
| path_or_fileobj="model.pt", # | |
| path_in_repo="model.pt", | |
| repo_id=HF_REPO, | |
| repo_type="model" | |
| ) | |
| print("Uploaded successfully!") | |
| ====================================================Load model.pt in your Flask backend | |
| pip install huggingface_hub torch | |
| import torch | |
| from huggingface_hub import hf_hub_download | |
| HF_REPO = "hf_username/reo_name" | |
| model_path = hf_hub_download( | |
| repo_id=HF_REPO, | |
| filename="model.pt" | |
| ) | |
| model = torch.jit.load(model_path, map_location="cpu") | |
| model.eval() | |
| print("Loaded successfully!") | |
| ===============================================================Usage | |
| def predict(input_data): | |
| x = scaler.transform([input_data]) | |
| x_tensor = torch.tensor(x, dtype=torch.float32) | |
| with torch.no_grad(): | |
| output = model(x_tensor) | |
| return output.numpy() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment