Update app.py
Browse files
app.py
CHANGED
@@ -118,20 +118,20 @@ class ModelConverter:
|
|
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
|
123 |
try:
|
124 |
-
#
|
125 |
-
|
126 |
|
127 |
-
#
|
128 |
-
|
129 |
-
return "ONNX folder not found. Conversion may have failed."
|
130 |
|
131 |
-
# Upload the
|
132 |
self.api.upload_folder(
|
133 |
-
folder_path=str(
|
134 |
-
repo_id=
|
|
|
135 |
)
|
136 |
return None
|
137 |
except Exception as e:
|
@@ -139,8 +139,7 @@ class ModelConverter:
|
|
139 |
finally:
|
140 |
import shutil
|
141 |
|
142 |
-
|
143 |
-
shutil.rmtree(onnx_folder_path, ignore_errors=True)
|
144 |
|
145 |
|
146 |
def main():
|
@@ -165,10 +164,12 @@ def main():
|
|
165 |
key="user_hf_token",
|
166 |
)
|
167 |
|
168 |
-
|
|
|
|
|
169 |
|
170 |
-
st.write(f"URL where the ONNX
|
171 |
-
st.code(output_model_url, language="plaintext")
|
172 |
|
173 |
if not st.button(label="Proceed", type="primary"):
|
174 |
return
|
@@ -182,15 +183,19 @@ def main():
|
|
182 |
st.success("Conversion successful!")
|
183 |
st.code(stderr)
|
184 |
|
185 |
-
with st.spinner("Uploading
|
186 |
-
error = converter.upload_model(input_model_id)
|
187 |
if error:
|
188 |
st.error(f"Upload failed: {error}")
|
189 |
return
|
190 |
|
191 |
st.success("Upload successful!")
|
192 |
-
st.write("
|
193 |
-
st.link_button(
|
|
|
|
|
|
|
|
|
194 |
|
195 |
except Exception as e:
|
196 |
logger.exception("Application error")
|
|
|
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:
|
|
|
139 |
finally:
|
140 |
import shutil
|
141 |
|
142 |
+
shutil.rmtree(model_folder_path, ignore_errors=True)
|
|
|
143 |
|
144 |
|
145 |
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
|
|
|
183 |
st.success("Conversion successful!")
|
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")
|