Update app.py
Browse files
app.py
CHANGED
@@ -92,23 +92,39 @@ class ModelConverter:
|
|
92 |
extracted_folder = next(Path(tmp_dir).iterdir())
|
93 |
extracted_folder.rename(self.config.repo_path)
|
94 |
|
95 |
-
def convert_model(self, input_model_id: str) -> Tuple[bool, Optional[str]]:
|
96 |
"""Convert the model to ONNX format."""
|
97 |
try:
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
if result.returncode != 0:
|
114 |
return False, result.stderr
|
@@ -177,6 +193,9 @@ def main():
|
|
177 |
type="password",
|
178 |
key="user_hf_token",
|
179 |
)
|
|
|
|
|
|
|
180 |
|
181 |
if config.hf_username == input_model_id.split("/")[0]:
|
182 |
same_repo = st.checkbox(
|
@@ -206,7 +225,7 @@ def main():
|
|
206 |
return
|
207 |
|
208 |
with st.spinner("Converting model..."):
|
209 |
-
success, stderr = converter.convert_model(input_model_id)
|
210 |
if not success:
|
211 |
st.error(f"Conversion failed: {stderr}")
|
212 |
return
|
|
|
92 |
extracted_folder = next(Path(tmp_dir).iterdir())
|
93 |
extracted_folder.rename(self.config.repo_path)
|
94 |
|
95 |
+
def convert_model(self, input_model_id: str, trust_remote_code=False) -> Tuple[bool, Optional[str]]:
|
96 |
"""Convert the model to ONNX format."""
|
97 |
try:
|
98 |
+
if trust_remote_code:
|
99 |
+
result = subprocess.run(
|
100 |
+
[
|
101 |
+
sys.executable,
|
102 |
+
"-m",
|
103 |
+
"scripts.convert",
|
104 |
+
"--quantize",
|
105 |
+
"--model_id",
|
106 |
+
input_model_id,
|
107 |
+
],
|
108 |
+
cwd=self.config.repo_path,
|
109 |
+
capture_output=True,
|
110 |
+
text=True,
|
111 |
+
env={},
|
112 |
+
)
|
113 |
+
else:
|
114 |
+
result = subprocess.run(
|
115 |
+
[
|
116 |
+
sys.executable,
|
117 |
+
"-m",
|
118 |
+
"scripts.convert",
|
119 |
+
"--quantize",
|
120 |
+
"--model_id",
|
121 |
+
input_model_id,
|
122 |
+
],
|
123 |
+
cwd=self.config.repo_path,
|
124 |
+
capture_output=True,
|
125 |
+
text=True,
|
126 |
+
env={},
|
127 |
+
)
|
128 |
|
129 |
if result.returncode != 0:
|
130 |
return False, result.stderr
|
|
|
193 |
type="password",
|
194 |
key="user_hf_token",
|
195 |
)
|
196 |
+
trust_remote_code = st.toggle("Trust Remote Code?")
|
197 |
+
if trust_remote_code:
|
198 |
+
st.warning("Remote code could be used for malicious purposes. Make sure you trust the code fully."
|
199 |
|
200 |
if config.hf_username == input_model_id.split("/")[0]:
|
201 |
same_repo = st.checkbox(
|
|
|
225 |
return
|
226 |
|
227 |
with st.spinner("Converting model..."):
|
228 |
+
success, stderr = converter.convert_model(input_model_id, trust_remote_code=trust_remote_code)
|
229 |
if not success:
|
230 |
st.error(f"Conversion failed: {stderr}")
|
231 |
return
|