Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -317,21 +317,34 @@ with gr.Blocks(theme="soft") as demo:
|
|
317 |
adv_btn = gr.Button("Download & Compare File")
|
318 |
adv_result = gr.Textbox(label="Bitwise Comparison Result", lines=3, interactive=False)
|
319 |
|
320 |
-
def adv_compare(m1, m2, fname, progress=gr.Progress(
|
321 |
if not m1 or not m2 or not fname:
|
322 |
return "Please provide both model IDs and the file name."
|
|
|
|
|
|
|
323 |
url1 = f"https://huggingface.co/{m1}/resolve/main/{fname}?download=true"
|
324 |
url2 = f"https://huggingface.co/{m2}/resolve/main/{fname}?download=true"
|
|
|
325 |
with tempfile.TemporaryDirectory() as tmp:
|
326 |
f1 = os.path.join(tmp, "f1.safetensors")
|
327 |
f2 = os.path.join(tmp, "f2.safetensors")
|
|
|
|
|
328 |
ok1, err1 = download_file_with_progress(url1, f1, progress)
|
|
|
|
|
329 |
ok2, err2 = download_file_with_progress(url2, f2, progress)
|
|
|
330 |
if not ok1 or not ok2:
|
331 |
return f"Download error: {err1 or ''} {err2 or ''}"
|
|
|
|
|
332 |
percent, err = file_similarity(f1, f2)
|
333 |
if err:
|
334 |
return f"Comparison error: {err}"
|
|
|
|
|
335 |
return f"Similarity: {percent:.2f}% ({'identical' if percent==100 else 'different'})"
|
336 |
adv_btn.click(
|
337 |
fn=adv_compare,
|
|
|
317 |
adv_btn = gr.Button("Download & Compare File")
|
318 |
adv_result = gr.Textbox(label="Bitwise Comparison Result", lines=3, interactive=False)
|
319 |
|
320 |
+
def adv_compare(m1, m2, fname, progress=gr.Progress()):
|
321 |
if not m1 or not m2 or not fname:
|
322 |
return "Please provide both model IDs and the file name."
|
323 |
+
|
324 |
+
progress(0, desc="Starting download...")
|
325 |
+
|
326 |
url1 = f"https://huggingface.co/{m1}/resolve/main/{fname}?download=true"
|
327 |
url2 = f"https://huggingface.co/{m2}/resolve/main/{fname}?download=true"
|
328 |
+
|
329 |
with tempfile.TemporaryDirectory() as tmp:
|
330 |
f1 = os.path.join(tmp, "f1.safetensors")
|
331 |
f2 = os.path.join(tmp, "f2.safetensors")
|
332 |
+
|
333 |
+
progress(0.1, desc=f"Downloading from {m1}...")
|
334 |
ok1, err1 = download_file_with_progress(url1, f1, progress)
|
335 |
+
|
336 |
+
progress(0.5, desc=f"Downloading from {m2}...")
|
337 |
ok2, err2 = download_file_with_progress(url2, f2, progress)
|
338 |
+
|
339 |
if not ok1 or not ok2:
|
340 |
return f"Download error: {err1 or ''} {err2 or ''}"
|
341 |
+
|
342 |
+
progress(0.9, desc="Comparing files...")
|
343 |
percent, err = file_similarity(f1, f2)
|
344 |
if err:
|
345 |
return f"Comparison error: {err}"
|
346 |
+
|
347 |
+
progress(1.0, desc="Complete!")
|
348 |
return f"Similarity: {percent:.2f}% ({'identical' if percent==100 else 'different'})"
|
349 |
adv_btn.click(
|
350 |
fn=adv_compare,
|