File size: 2,036 Bytes
72c37b7
d0d4c5d
 
 
9568673
d0d4c5d
72c37b7
d0d4c5d
 
 
 
 
 
 
 
 
 
 
9568673
 
d0d4c5d
 
 
 
 
 
 
 
 
 
 
 
 
9568673
 
 
 
 
 
 
 
 
745cf6d
 
a0db052
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
43
44
45
46
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.text import Tokenizer
import json
from gradio import Interface

# Load model (replace with your actual path)
model = load_model("https://huggingface.co/Bajiyo/mal_en_transliteration/tree/main/transliteration_model.h5")

# Load tokenizers from configuration files (replace with your paths)
with open("https://huggingface.co/Bajiyo/mal_en_transliteration/tree/main/source_tokenizer_config.json", "r") as f:
    source_tokenizer_config = json.load(f)
source_tokenizer = Tokenizer(num_words=source_tokenizer_config["num_words"])
source_tokenizer.fit_on_texts(source_tokenizer_config["texts"])  # Assuming pre-defined texts

with open("https://huggingface.co/Bajiyo/mal_en_transliteration/tree/main/target_tokenizer_config.json", "r") as f:
    target_tokenizer_config = json.load(f)
target_tokenizer = Tokenizer(num_words=target_tokenizer_config["num_words"])
target_tokenizer.fit_on_texts(target_tokenizer_config["texts"])  # Assuming pre-defined texts

def translate(malayalam_text):
    # Preprocessing (tokenization)
    source_tokens = source_tokenizer.texts_to_sequences([malayalam_text])[0]

    # Padding (adjust maxlen based on your model's requirements)
    maxlen = 100  # Example value, adjust as needed
    padded_text = pad_sequences([source_tokens], maxlen=maxlen, padding="post")

    # Make predictions using the model
    predictions = model.predict(padded_text)

    # Postprocessing (decoding)
    english_text = target_tokenizer.sequences_to_texts([predictions[0]])[0]

    return english_text

interface = gradio.Interface(
    fn=translate,
    inputs="text",
    outputs="text",
    title="Malayalam to English Transliteration",
    description="Enter Malayalam text to get the English transliteration.",
    examples=[["എങ്ങനെയാണ് ഞാൻ ഇംഗ്ലീഷിൽ സംസാരിക്കേണ്ടത്?"], ["ഹലോ എങ്ങനെയിരിക്കുന്നു?"]]
)

interface.launch()