Aditya Sahu
commited on
Renaming logic for uploaded model
Browse files
app.py
CHANGED
|
@@ -55,11 +55,21 @@ def compile_model(model_name, vmem_value, lpmem_value, uploaded_model):
|
|
| 55 |
|
| 56 |
# Run the model fitter with better error handling
|
| 57 |
try:
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
print(f"VMEM limit: {vmem_size_limit}, LPMEM limit: {lpmem_size_limit}")
|
| 60 |
|
| 61 |
success, results = sr100_model_compiler.sr100_model_optimizer(
|
| 62 |
-
model_file=
|
| 63 |
vmem_size_limit=vmem_size_limit,
|
| 64 |
lpmem_size_limit=lpmem_size_limit
|
| 65 |
)
|
|
@@ -83,14 +93,6 @@ def compile_model(model_name, vmem_value, lpmem_value, uploaded_model):
|
|
| 83 |
"❌ ERROR: Model optimization failed</div>"
|
| 84 |
"<div style='margin-top:0.5em;color:#000;'>Error details:</div>"
|
| 85 |
f"<pre style='white-space:pre-wrap; background:#f6f8fa; padding:8px; border-radius:6px; color:#000;'>{html.escape(error_message)}</pre>"
|
| 86 |
-
"<div style='margin-top:0.5em;color:#000;'>"
|
| 87 |
-
"Common reasons for failure:"
|
| 88 |
-
"<ul style='margin:0.5em 0 0 1.2em;'>"
|
| 89 |
-
"<li>Model contains unsupported operations for SR100 NPU</li>"
|
| 90 |
-
"<li>Model is not properly quantized to INT8</li>"
|
| 91 |
-
"<li>Memory limits are too restrictive for the model size</li>"
|
| 92 |
-
"</ul>"
|
| 93 |
-
"</div>"
|
| 94 |
)
|
| 95 |
|
| 96 |
output = []
|
|
@@ -221,12 +223,10 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 221 |
gr.Markdown("<h1 style='font-size:2.5em; color:#007dc3; margin-bottom:0;'>SR100 Model Compiler</h1>", elem_id="main_title")
|
| 222 |
gr.Markdown("<h3 style='margin-top:0; color:#000;'>Bring a TFlite INT8 model and compile it for Synaptics Astra SR100. Learn more at <a href='https://developer.synaptics.com/docs/sr/sr100/quick-start?utm_source=hf' target='_blank' style='color:#007dc3; text-decoration:underline;'>Synaptics AI Developer Zone</a></h3>", elem_id="subtitle")
|
| 223 |
|
| 224 |
-
# Setup model inputs
|
| 225 |
with gr.Row():
|
| 226 |
vmem_slider = gr.Slider(minimum=0, maximum=1536, step=1.024, label="Set total VMEM SRAM size available in kB", value=1536.0)
|
| 227 |
lpmem_slider = gr.Slider(minimum=0, maximum=1536, step=1.024, label="Set total LPMEM SRAM size in kB", value=1536.0)
|
| 228 |
|
| 229 |
-
# Setup model selection/upload
|
| 230 |
model_dropdown = gr.Dropdown(
|
| 231 |
label="Select a model",
|
| 232 |
value='models/hello_world.tflite',
|
|
|
|
| 55 |
|
| 56 |
# Run the model fitter with better error handling
|
| 57 |
try:
|
| 58 |
+
original_file_name = os.path.basename(model_path)
|
| 59 |
+
root, ext = os.path.splitext(original_file_name)
|
| 60 |
+
safe_root = root.replace('.', '_')
|
| 61 |
+
model_file_name = f"{safe_root}{ext}"
|
| 62 |
+
temp_model_path = os.path.join(out_dir, model_file_name)
|
| 63 |
+
|
| 64 |
+
print(f"Copying model to sanitized path: {temp_model_path}")
|
| 65 |
+
with open(model_path, "rb") as src, open(temp_model_path, "wb") as dst:
|
| 66 |
+
dst.write(src.read())
|
| 67 |
+
|
| 68 |
+
print(f"Starting model optimization for {temp_model_path}")
|
| 69 |
print(f"VMEM limit: {vmem_size_limit}, LPMEM limit: {lpmem_size_limit}")
|
| 70 |
|
| 71 |
success, results = sr100_model_compiler.sr100_model_optimizer(
|
| 72 |
+
model_file=temp_model_path,
|
| 73 |
vmem_size_limit=vmem_size_limit,
|
| 74 |
lpmem_size_limit=lpmem_size_limit
|
| 75 |
)
|
|
|
|
| 93 |
"❌ ERROR: Model optimization failed</div>"
|
| 94 |
"<div style='margin-top:0.5em;color:#000;'>Error details:</div>"
|
| 95 |
f"<pre style='white-space:pre-wrap; background:#f6f8fa; padding:8px; border-radius:6px; color:#000;'>{html.escape(error_message)}</pre>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
)
|
| 97 |
|
| 98 |
output = []
|
|
|
|
| 223 |
gr.Markdown("<h1 style='font-size:2.5em; color:#007dc3; margin-bottom:0;'>SR100 Model Compiler</h1>", elem_id="main_title")
|
| 224 |
gr.Markdown("<h3 style='margin-top:0; color:#000;'>Bring a TFlite INT8 model and compile it for Synaptics Astra SR100. Learn more at <a href='https://developer.synaptics.com/docs/sr/sr100/quick-start?utm_source=hf' target='_blank' style='color:#007dc3; text-decoration:underline;'>Synaptics AI Developer Zone</a></h3>", elem_id="subtitle")
|
| 225 |
|
|
|
|
| 226 |
with gr.Row():
|
| 227 |
vmem_slider = gr.Slider(minimum=0, maximum=1536, step=1.024, label="Set total VMEM SRAM size available in kB", value=1536.0)
|
| 228 |
lpmem_slider = gr.Slider(minimum=0, maximum=1536, step=1.024, label="Set total LPMEM SRAM size in kB", value=1536.0)
|
| 229 |
|
|
|
|
| 230 |
model_dropdown = gr.Dropdown(
|
| 231 |
label="Select a model",
|
| 232 |
value='models/hello_world.tflite',
|