Spaces:
Configuration error
Configuration error
Commit ·
161e02f
1
Parent(s): ba6dce9
gradio app basic works
Browse files- app.py +17 -0
- model_lr0.0001_bs256_epoch50.pt +3 -0
- src/evaluator.py +15 -0
- webapp/__init__.py +0 -0
app.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
import src.evaluator as evaluator
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def compress(text):
|
| 7 |
+
return evaluator.evaluate(text, compression=True)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
with gr.Blocks() as demo:
|
| 11 |
+
raw_text = gr.Textbox(label="Raw Text", )
|
| 12 |
+
compressed_textbox = gr.Textbox(label="Compressed")
|
| 13 |
+
metadata_textbox = gr.Textbox(label="Report")
|
| 14 |
+
btn = gr.Button("Compress")
|
| 15 |
+
btn.click(fn=compress, inputs=raw_text, outputs=[compressed_textbox, metadata_textbox], api_name="compress")
|
| 16 |
+
|
| 17 |
+
demo.launch()
|
model_lr0.0001_bs256_epoch50.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:31923ca96e3c2471ad6252dfb615b15cde784be5a7792c7379d1c9a9b27a7f4e
|
| 3 |
+
size 551468733
|
src/evaluator.py
CHANGED
|
@@ -13,3 +13,18 @@ def evaluate(args):
|
|
| 13 |
print(decompress(args.text, Tokenizer(vocab), model))
|
| 14 |
else:
|
| 15 |
print(compress(args.text, Tokenizer(vocab), model))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
print(decompress(args.text, Tokenizer(vocab), model))
|
| 14 |
else:
|
| 15 |
print(compress(args.text, Tokenizer(vocab), model))
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def evaluate(text, compression=True):
|
| 19 |
+
vocab = torch.load("vocab.pt", map_location=torch.device('cpu'))
|
| 20 |
+
model = Model2(len(vocab), 300, 256, vocab['<PAD>'])
|
| 21 |
+
load_from_checkpoint(model, "model_lr0.0001_bs256_epoch50.pt")
|
| 22 |
+
|
| 23 |
+
if not compression:
|
| 24 |
+
result = decompress(text, Tokenizer(vocab), model)
|
| 25 |
+
else:
|
| 26 |
+
result = compress(text, Tokenizer(vocab), model)
|
| 27 |
+
|
| 28 |
+
# calculate the compression ratio from string lengths
|
| 29 |
+
compression_ratio = (1 - (len(result) / len(text))) * 100
|
| 30 |
+
return result, f"{compression_ratio}% compressed"
|
webapp/__init__.py
ADDED
|
File without changes
|