Arrcttacsrks commited on
Commit
47b0e83
·
verified ·
1 Parent(s): 707d832

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -3
app.py CHANGED
@@ -9,6 +9,7 @@ import onnx.numpy_helper
9
  from huggingface_hub import HfApi
10
  from tempfile import NamedTemporaryFile
11
  import time
 
12
 
13
  def analyze_weight_data(tensor):
14
  """Analyze tensor data"""
@@ -150,7 +151,22 @@ def format_analysis_text(analysis):
150
  return text
151
 
152
  def save_to_hf_dataset(analysis, model_name):
153
- """Save analysis results to Hugging Face dataset"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  api = HfApi()
155
 
156
  # Create temporary files
@@ -163,7 +179,7 @@ def save_to_hf_dataset(analysis, model_name):
163
  with NamedTemporaryFile(mode='w', suffix='.json', delete=False) as json_file:
164
  json.dump(analysis, json_file, indent=2)
165
  json_path = json_file.name
166
-
167
  try:
168
  # Upload files to dataset
169
  api.upload_file(
@@ -175,10 +191,11 @@ def save_to_hf_dataset(analysis, model_name):
175
 
176
  api.upload_file(
177
  path_or_fileobj=json_path,
178
- path_in_repo=f"analysis_{model_name}_{timestamp}.json",
179
  repo_id="Arrcttacsrks/OnnxAnalysisData",
180
  repo_type="dataset"
181
  )
 
182
  finally:
183
  # Clean up temporary files
184
  os.unlink(txt_path)
 
9
  from huggingface_hub import HfApi
10
  from tempfile import NamedTemporaryFile
11
  import time
12
+ from huggingface_hub import HfApi, login
13
 
14
  def analyze_weight_data(tensor):
15
  """Analyze tensor data"""
 
151
  return text
152
 
153
  def save_to_hf_dataset(analysis, model_name):
154
+ """
155
+ Save analysis results to Hugging Face dataset using token from environment variable
156
+
157
+ Args:
158
+ analysis: Analysis results to save
159
+ model_name: Name of the model being analyzed
160
+ """
161
+ # Get token from environment variable
162
+ hf_token = os.getenv('HF_TOKEN')
163
+ if not hf_token:
164
+ raise ValueError("HF_TOKEN environment variable not found")
165
+
166
+ # Login with token
167
+ login(token=hf_token)
168
+
169
+ # Initialize API
170
  api = HfApi()
171
 
172
  # Create temporary files
 
179
  with NamedTemporaryFile(mode='w', suffix='.json', delete=False) as json_file:
180
  json.dump(analysis, json_file, indent=2)
181
  json_path = json_file.name
182
+
183
  try:
184
  # Upload files to dataset
185
  api.upload_file(
 
191
 
192
  api.upload_file(
193
  path_or_fileobj=json_path,
194
+ path_in_repo=f"analysis_{model_name}_{timestamp}.json",
195
  repo_id="Arrcttacsrks/OnnxAnalysisData",
196
  repo_type="dataset"
197
  )
198
+
199
  finally:
200
  # Clean up temporary files
201
  os.unlink(txt_path)