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()