Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,2 +1,51 @@
|
|
| 1 |
-
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from gradio import Interface
|
| 2 |
+
import json
|
| 3 |
+
from tensorflow.keras.models import load_model # Assuming TensorFlow backend
|
| 4 |
+
from keras.preprocessing.text import Tokenizer # Assuming Keras Tokenizer
|
| 5 |
+
|
| 6 |
+
# Model and tokenizer loading paths (replace with your actual paths)
|
| 7 |
+
model_path = "Bajiyo/Malayalam_transliteration"
|
| 8 |
+
source_tokenizer_config_path = "Bajiyo/Malayalam_transliteration"
|
| 9 |
+
target_tokenizer_config_path = "Bajiyo/Malayalam_transliteration"
|
| 10 |
+
|
| 11 |
+
# Load the model
|
| 12 |
+
model = load_model(model_path)
|
| 13 |
+
|
| 14 |
+
# Load tokenizers
|
| 15 |
+
with open(source_tokenizer_config_path, "r") as f:
|
| 16 |
+
source_tokenizer = Tokenizer.from_config(json.load(f))
|
| 17 |
+
|
| 18 |
+
with open(target_tokenizer_config_path, "r") as f:
|
| 19 |
+
target_tokenizer = Tokenizer.from_config(json.load(f))
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def transliterate(malayalam_name):
|
| 23 |
+
# Preprocess input (e.g., handle punctuation, special characters)
|
| 24 |
+
processed_name = preprocess_malayalam_name(malayalam_name) # Implement your preprocessing logic
|
| 25 |
+
|
| 26 |
+
# Tokenize the input
|
| 27 |
+
sequence = source_tokenizer.texts_to_sequences([processed_name])[0]
|
| 28 |
+
|
| 29 |
+
# Pad the sequence
|
| 30 |
+
padded_sequence = pad_sequences([sequence], maxlen=MAX_SEQ_LENGTH, padding="post")
|
| 31 |
+
|
| 32 |
+
# Make prediction
|
| 33 |
+
prediction = model.predict(padded_sequence)[0]
|
| 34 |
+
|
| 35 |
+
# Detokenize the predicted sequence
|
| 36 |
+
transliterated_name = target_tokenizer.sequences_to_texts([np.argmax(prediction)])[0]
|
| 37 |
+
|
| 38 |
+
return transliterated_name
|
| 39 |
+
|
| 40 |
+
# Define the maximum sequence length your model was trained on
|
| 41 |
+
MAX_SEQ_LENGTH = ... # Replace with the actual value
|
| 42 |
+
|
| 43 |
+
interface = Interface(
|
| 44 |
+
fn=transliterate,
|
| 45 |
+
inputs="text",
|
| 46 |
+
outputs="text",
|
| 47 |
+
title="Malayalam to English Transliteration",
|
| 48 |
+
description="Enter a Malayalam name and get the transliterated English version.",
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
interface.launch()
|