File size: 1,952 Bytes
ea057f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import glob
import os
from tokenizers import Tokenizer
import gradio as gr

# Load the tokenizer
tokenizer = Tokenizer.from_file("tamil_bpe_tokenizer.json")

# Define the compression ratio function
def compression_ratio(text):
    encoded = tokenizer.encode(text)
    compressed_length = len(encoded.ids)
    original_length = len(text)
    compression = original_length / compressed_length
    decoded_text = tokenizer.decode(encoded.ids)
    
    encoded_tokens = encoded.tokens
    vocab_size = len(tokenizer.get_vocab())
    
    return encoded_tokens, vocab_size, compression, decoded_text

# Sample text
sample_text1 = "இந்நூலை வாசித்ததிலிருந்து நிறையவே தெரிந்துகொண்டேன்"
sample_text2 = "தனக்குக் கிடைக்கின்ற நேரத்தை சில மனிதர்கள் வீணடிக்காமல் சரியாகப் பயன்படுத்திக்கொள்கின்றார்கள்."
sample_text3 = "Google Play-store ஐ திறந்து Battle Royal Game-களின் தரவிறக்கங்களின் எண்ணிக்கையைப் பாருங்கள். 1Billion, 500Million என சமூக வலைத்தளங்களை பயன்படுத்துவோரின் எண்ணிக்கைக்கு சமனாக இருக்கும்."

# Define the Gradio interface
iface = gr.Interface(
    fn=compression_ratio,
    inputs=gr.Textbox(lines=5, placeholder="Enter text here..."),
    examples=[[sample_text1], [sample_text2], [sample_text3]],
    outputs=[
        gr.JSON(label="Encoded Text"),
        gr.Textbox(label="Vocabulary Size"),
        gr.Textbox(label="Compression Ratio"),
        gr.Textbox(label="Decoded Text")
    ]
)

# Launch the interface
if __name__ == "__main__":
    iface.launch()