Bajiyo's picture
Update app.py
d18faba verified
raw
history blame
No virus
1.17 kB
import gradio as gr
from keras.models import load_model
from keras.preprocessing.sequence import pad_sequences
from keras.preprocessing.text import Tokenizer
# Load your custom Keras model
model = load_model('/content/drive/MyDrive/best_model.h5')
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()