rahul7star commited on
Commit
c52fd8f
Β·
verified Β·
1 Parent(s): 0deec1a

Update app_flash.py

Browse files
Files changed (1) hide show
  1. app_flash.py +16 -9
app_flash.py CHANGED
@@ -70,35 +70,42 @@ from huggingface_hub import hf_hub_download, HfApi
70
  import os
71
  import tempfile
72
  from flashpack import FlashPackMixin
73
- from huggingface_hub import hf_hub_upload
 
 
 
 
 
 
74
 
75
  def push_flashpack_to_hub_local(model: FlashPackMixin, hf_repo: str):
76
  logs = []
77
 
78
- # Create a temporary directory for the pack
79
  with tempfile.TemporaryDirectory() as tmp_dir:
80
  logs.append(f"πŸ“‚ Using temporary directory: {tmp_dir}")
81
 
82
- # Ensure a proper file path (not just a directory)
83
  pack_file = os.path.join(tmp_dir, "model.pack")
84
  logs.append(f"πŸ’Ύ Saving FlashPack model to: {pack_file}")
85
 
86
- # Save the model
87
  model.save_flashpack(pack_file, target_dtype=torch.float32)
88
  logs.append("βœ… Model saved successfully.")
89
 
90
- # Upload to HF Hub
91
  logs.append(f"🌐 Uploading {pack_file} to Hugging Face repo: {hf_repo}")
92
- hf_hub_upload(
93
- repo_id=hf_repo,
94
- path_or_fileobj=pack_file,
95
  path_in_repo="model.pack", # filename in the repo
 
96
  repo_type="model",
97
- token=os.environ.get("HF_TOKEN") # make sure HF_TOKEN is set
98
  )
99
  logs.append("πŸš€ Upload successful!")
100
 
101
  return logs
 
 
 
102
  def train_and_push_flashpack(
103
  dataset_name: str = "gokaygokay/prompt-enhancer-dataset",
104
  hf_repo: str = "rahul7star/FlashPack",
 
70
  import os
71
  import tempfile
72
  from flashpack import FlashPackMixin
73
+ #from huggingface_hub import hf_hub_upload
74
+
75
+ from huggingface_hub import upload_file
76
+ import os
77
+ import tempfile
78
+ from flashpack import FlashPackMixin
79
+ import torch
80
 
81
  def push_flashpack_to_hub_local(model: FlashPackMixin, hf_repo: str):
82
  logs = []
83
 
 
84
  with tempfile.TemporaryDirectory() as tmp_dir:
85
  logs.append(f"πŸ“‚ Using temporary directory: {tmp_dir}")
86
 
87
+ # Save to a proper file path
88
  pack_file = os.path.join(tmp_dir, "model.pack")
89
  logs.append(f"πŸ’Ύ Saving FlashPack model to: {pack_file}")
90
 
 
91
  model.save_flashpack(pack_file, target_dtype=torch.float32)
92
  logs.append("βœ… Model saved successfully.")
93
 
94
+ # Upload to Hugging Face Hub
95
  logs.append(f"🌐 Uploading {pack_file} to Hugging Face repo: {hf_repo}")
96
+ upload_file(
97
+ path_or_file=pack_file,
 
98
  path_in_repo="model.pack", # filename in the repo
99
+ repo_id=hf_repo,
100
  repo_type="model",
101
+ token=os.environ.get("HF_TOKEN") # ensure HF_TOKEN is set
102
  )
103
  logs.append("πŸš€ Upload successful!")
104
 
105
  return logs
106
+
107
+
108
+
109
  def train_and_push_flashpack(
110
  dataset_name: str = "gokaygokay/prompt-enhancer-dataset",
111
  hf_repo: str = "rahul7star/FlashPack",