prithivMLmods commited on
Commit
41daa2f
·
verified ·
1 Parent(s): 8f89fd9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -23
app.py CHANGED
@@ -118,20 +118,25 @@ class ModelConverter:
118
  except Exception as e:
119
  return False, str(e)
120
 
121
- def upload_model(self, input_model_id: str, output_model_id: str) -> Optional[str]:
122
- """Upload the converted model to Hugging Face under the 'onnx/' subfolder."""
123
  try:
124
- # Ensure the repository exists (no need to create a new one)
125
- self.api.repo_exists(output_model_id, repo_type="model")
126
-
127
- # Define the path to the converted model folder
128
  model_folder_path = self.config.repo_path / "models" / input_model_id
 
 
 
 
 
 
 
 
 
129
 
130
- # Upload the folder to the 'onnx/' subfolder in the existing repository
131
  self.api.upload_folder(
132
- folder_path=str(model_folder_path),
133
- repo_id=output_model_id,
134
- path_in_repo="onnx", # Upload to the 'onnx/' subfolder
135
  )
136
  return None
137
  except Exception as e:
@@ -164,12 +169,7 @@ def main():
164
  key="user_hf_token",
165
  )
166
 
167
- # Use the same model ID for the output (no need to append '-ONNX')
168
- output_model_id = input_model_id
169
- output_model_url = f"{config.hf_base_url}/{output_model_id}"
170
-
171
- st.write(f"URL where the ONNX model will be uploaded to:")
172
- st.code(f"{output_model_url}/tree/onnx", language="plaintext")
173
 
174
  if not st.button(label="Proceed", type="primary"):
175
  return
@@ -184,18 +184,14 @@ def main():
184
  st.code(stderr)
185
 
186
  with st.spinner("Uploading model..."):
187
- error = converter.upload_model(input_model_id, output_model_id)
188
  if error:
189
  st.error(f"Upload failed: {error}")
190
  return
191
 
192
  st.success("Upload successful!")
193
- st.write("You can now go and view the ONNX model on Hugging Face!")
194
- st.link_button(
195
- f"Go to {output_model_id}/onnx",
196
- f"{output_model_url}/tree/onnx",
197
- type="primary",
198
- )
199
 
200
  except Exception as e:
201
  logger.exception("Application error")
 
118
  except Exception as e:
119
  return False, str(e)
120
 
121
+ def upload_model(self, input_model_id: str) -> Optional[str]:
122
+ """Upload the converted model to the `onnx/` subfolder in the existing model repository."""
123
  try:
 
 
 
 
124
  model_folder_path = self.config.repo_path / "models" / input_model_id
125
+ onnx_folder_path = model_folder_path / "onnx"
126
+
127
+ # Create the `onnx` subfolder if it doesn't exist
128
+ onnx_folder_path.mkdir(exist_ok=True)
129
+
130
+ # Move the ONNX files to the `onnx` subfolder
131
+ for file in model_folder_path.iterdir():
132
+ if file.is_file() and file.suffix == ".onnx":
133
+ file.rename(onnx_folder_path / file.name)
134
 
135
+ # Upload the `onnx` subfolder to the existing repository
136
  self.api.upload_folder(
137
+ folder_path=str(onnx_folder_path),
138
+ repo_id=input_model_id,
139
+ path_in_repo="onnx",
140
  )
141
  return None
142
  except Exception as e:
 
169
  key="user_hf_token",
170
  )
171
 
172
+ output_model_url = f"{config.hf_base_url}/{input_model_id}"
 
 
 
 
 
173
 
174
  if not st.button(label="Proceed", type="primary"):
175
  return
 
184
  st.code(stderr)
185
 
186
  with st.spinner("Uploading model..."):
187
+ error = converter.upload_model(input_model_id)
188
  if error:
189
  st.error(f"Upload failed: {error}")
190
  return
191
 
192
  st.success("Upload successful!")
193
+ st.write("You can now go and view the model on Hugging Face!")
194
+ st.link_button(f"Go to {input_model_id}", output_model_url, type="primary")
 
 
 
 
195
 
196
  except Exception as e:
197
  logger.exception("Application error")