File size: 1,501 Bytes
080b5e3
 
613cb95
080b5e3
 
 
 
 
ade2af2
 
 
080b5e3
97bb6da
613cb95
 
 
4beb772
613cb95
0688df4
 
97a5957
 
4beb772
 
 
97a5957
4beb772
8d9fe38
d18faba
 
97a5957
4beb772
97a5957
 
 
 
 
 
 
 
 
 
0688df4
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
import subprocess
import sys
import os

# Install TensorFlow
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'tensorflow'])

# Now import the required modules
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.preprocessing.text import Tokenizer
import gradio as gr

# Define the path to the model file in the /mnt/data/ directory
model_path = '/mnt/data/models/Bajiyo/Named_entity_transliteration_malayalam/best_model.h5'

# Load your custom Keras model
model = load_model(model_path)
tokenizer = source_tokenizer

# Function for transliteration
def transliterate_malayalam_to_english(malayalam_text):
    # Tokenize and preprocess the input (adjust this based on your preprocessing logic)
    input_sequence = pad_sequences(tokenizer.texts_to_sequences([malayalam_text]), maxlen=max_seq_length, padding='post')
    
    # Use the model for prediction
    output_sequence = model.predict(input_sequence)
    
    # Use argmax to get the most likely characters
    predicted_text = "".join([tokenizer.index_word[idx] for idx in np.argmax(output_sequence, axis=-1)[0] if idx != 0])
    
    return predicted_text

# Create a Gradio interface
iface = gr.Interface(
    fn=transliterate_malayalam_to_english,
    inputs=gr.Textbox(prompt="Enter Malayalam Text", lines=5),
    outputs=gr.Textbox(prompt="Transliterated English Text", lines=5),
    live=True
)

# Launch the Gradio interface
iface.launch()