Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
-
"""Nacrith -- Neural Arithmetic Compression -- Hugging Face Space Demo.
|
| 3 |
|
| 4 |
Supports both text (NC01) and binary (NC02) compression.
|
| 5 |
"""
|
|
@@ -78,9 +78,9 @@ def compress_text(text):
|
|
| 78 |
|---|---|---|
|
| 79 |
| **Original** | {format_size(original_bytes)} | 100% |
|
| 80 |
| **gzip -9** | {format_size(gzip_size)} | {gzip_ratio:.1f}% |
|
| 81 |
-
| **Nacrith** | {format_size(compressed_size)} | {ratio:.1f}% |
|
| 82 |
|
| 83 |
-
**Nacrith is {improvement:.1f}x smaller than gzip**
|
| 84 |
|
| 85 |
Tokens: {num_tokens} | Time: {elapsed:.1f}s ({tokens_per_sec:.0f} tok/s) | Lossless: {verify} | Space saved: {100 - ratio:.1f}%
|
| 86 |
"""
|
|
@@ -169,9 +169,9 @@ def compress_file_b64(b64_data, filename):
|
|
| 169 |
|---|---|---|
|
| 170 |
| **Original** | {format_size(original_size)} | 100% |
|
| 171 |
| **gzip -9** | {format_size(gzip_size)} | {gzip_ratio:.1f}% |
|
| 172 |
-
| **Nacrith** | {format_size(compressed_size)} | {ratio:.1f}% |
|
| 173 |
|
| 174 |
-
**Nacrith is {improvement:.1f}x smaller than gzip**
|
| 175 |
|
| 176 |
Mode: {mode_label} | Time: {elapsed:.1f}s | Lossless: {verify} | Space saved: {100 - ratio:.1f}%
|
| 177 |
"""
|
|
@@ -195,11 +195,11 @@ Mode: {mode_label} | Time: {elapsed:.1f}s | Lossless: {verify} | Space saved: {1
|
|
| 195 |
def _decompress_data(data):
|
| 196 |
"""Shared decompression logic. Returns (md, download_html, text)."""
|
| 197 |
if len(data) < HEADER_SIZE:
|
| 198 |
-
return "**Invalid data.** Too short to be a Nacrith compressed file.", "", ""
|
| 199 |
|
| 200 |
magic = data[:4]
|
| 201 |
if magic not in (MAGIC, MAGIC_BIN):
|
| 202 |
-
return "**Invalid data.** Not a Nacrith compressed file (wrong magic bytes).", "", ""
|
| 203 |
|
| 204 |
comp = get_compressor()
|
| 205 |
is_binary = magic == MAGIC_BIN
|
|
@@ -293,11 +293,11 @@ def decompress_b64(b64_text):
|
|
| 293 |
|
| 294 |
HEADER_HTML = """
|
| 295 |
<div style="text-align: center; margin-bottom: 0.5em;">
|
| 296 |
-
<img src="https://raw.githubusercontent.com/st4ck/Nacrith/main/assets/
|
| 297 |
<p style="font-size: 1.1em; color: #aaa; margin-top: 8px;">Neural Arithmetic Compression -- State-of-the-Art Lossless Encoding</p>
|
| 298 |
<p style="font-size: 0.9em;">
|
| 299 |
<a href="https://nacrith.com">Website</a> |
|
| 300 |
-
<a href="https://github.com/st4ck/Nacrith">GitHub</a> |
|
| 301 |
SmolLM2-135M + Arithmetic Coding | Supports text & binary files
|
| 302 |
</p>
|
| 303 |
</div>
|
|
@@ -361,7 +361,7 @@ function setupNcUpload() {
|
|
| 361 |
setTimeout(setupNcUpload, 1200);
|
| 362 |
"""
|
| 363 |
|
| 364 |
-
with gr.Blocks(title="Nacrith") as demo:
|
| 365 |
gr.HTML(HEADER_HTML)
|
| 366 |
|
| 367 |
# ---- Tab 1: Compress Text ----
|
|
@@ -487,7 +487,7 @@ The same model runs on both sides, guaranteeing perfect lossless reconstruction.
|
|
| 487 |
**Binary (NC02):** Files are segmented into text-like and binary regions. Text regions are neural-compressed;
|
| 488 |
binary regions are compressed with gzip or lzma. The hybrid approach beats gzip on files with significant text content.
|
| 489 |
<br>
|
| 490 |
-
<img src="https://raw.githubusercontent.com/st4ck/Nacrith/main/assets/compression_ratio.png" alt="Compression Ratio Bar Charts">
|
| 491 |
<br>
|
| 492 |
Apache 2.0 | Made by [Roberto Tacconelli](https://github.com/st4ck)
|
| 493 |
""")
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
+
"""Nacrith GPU -- Neural Arithmetic Compression -- Hugging Face Space Demo.
|
| 3 |
|
| 4 |
Supports both text (NC01) and binary (NC02) compression.
|
| 5 |
"""
|
|
|
|
| 78 |
|---|---|---|
|
| 79 |
| **Original** | {format_size(original_bytes)} | 100% |
|
| 80 |
| **gzip -9** | {format_size(gzip_size)} | {gzip_ratio:.1f}% |
|
| 81 |
+
| **Nacrith GPU** | {format_size(compressed_size)} | {ratio:.1f}% |
|
| 82 |
|
| 83 |
+
**Nacrith GPU is {improvement:.1f}x smaller than gzip**
|
| 84 |
|
| 85 |
Tokens: {num_tokens} | Time: {elapsed:.1f}s ({tokens_per_sec:.0f} tok/s) | Lossless: {verify} | Space saved: {100 - ratio:.1f}%
|
| 86 |
"""
|
|
|
|
| 169 |
|---|---|---|
|
| 170 |
| **Original** | {format_size(original_size)} | 100% |
|
| 171 |
| **gzip -9** | {format_size(gzip_size)} | {gzip_ratio:.1f}% |
|
| 172 |
+
| **Nacrith GPU** | {format_size(compressed_size)} | {ratio:.1f}% |
|
| 173 |
|
| 174 |
+
**Nacrith GPU is {improvement:.1f}x smaller than gzip**
|
| 175 |
|
| 176 |
Mode: {mode_label} | Time: {elapsed:.1f}s | Lossless: {verify} | Space saved: {100 - ratio:.1f}%
|
| 177 |
"""
|
|
|
|
| 195 |
def _decompress_data(data):
|
| 196 |
"""Shared decompression logic. Returns (md, download_html, text)."""
|
| 197 |
if len(data) < HEADER_SIZE:
|
| 198 |
+
return "**Invalid data.** Too short to be a Nacrith GPU compressed file.", "", ""
|
| 199 |
|
| 200 |
magic = data[:4]
|
| 201 |
if magic not in (MAGIC, MAGIC_BIN):
|
| 202 |
+
return "**Invalid data.** Not a Nacrith GPU compressed file (wrong magic bytes).", "", ""
|
| 203 |
|
| 204 |
comp = get_compressor()
|
| 205 |
is_binary = magic == MAGIC_BIN
|
|
|
|
| 293 |
|
| 294 |
HEADER_HTML = """
|
| 295 |
<div style="text-align: center; margin-bottom: 0.5em;">
|
| 296 |
+
<img src="https://raw.githubusercontent.com/st4ck/Nacrith-GPU/main/assets/banner_gpu.png" alt="Nacrith GPU" style="max-width:420px;width:100%;margin:0 auto;">
|
| 297 |
<p style="font-size: 1.1em; color: #aaa; margin-top: 8px;">Neural Arithmetic Compression -- State-of-the-Art Lossless Encoding</p>
|
| 298 |
<p style="font-size: 0.9em;">
|
| 299 |
<a href="https://nacrith.com">Website</a> |
|
| 300 |
+
<a href="https://github.com/st4ck/Nacrith-GPU">GitHub</a> |
|
| 301 |
SmolLM2-135M + Arithmetic Coding | Supports text & binary files
|
| 302 |
</p>
|
| 303 |
</div>
|
|
|
|
| 361 |
setTimeout(setupNcUpload, 1200);
|
| 362 |
"""
|
| 363 |
|
| 364 |
+
with gr.Blocks(title="Nacrith GPU") as demo:
|
| 365 |
gr.HTML(HEADER_HTML)
|
| 366 |
|
| 367 |
# ---- Tab 1: Compress Text ----
|
|
|
|
| 487 |
**Binary (NC02):** Files are segmented into text-like and binary regions. Text regions are neural-compressed;
|
| 488 |
binary regions are compressed with gzip or lzma. The hybrid approach beats gzip on files with significant text content.
|
| 489 |
<br>
|
| 490 |
+
<img src="https://raw.githubusercontent.com/st4ck/Nacrith-GPU/main/assets/compression_ratio.png" alt="Compression Ratio Bar Charts">
|
| 491 |
<br>
|
| 492 |
Apache 2.0 | Made by [Roberto Tacconelli](https://github.com/st4ck)
|
| 493 |
""")
|