Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,51 +1,28 @@
|
|
1 |
-
|
2 |
-
import
|
3 |
-
from
|
4 |
-
#from keras.preprocessing.text import Tokenizer # Assuming Keras Tokenizer
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
source_tokenizer_config_path = "https://huggingface.co/Bajiyo/Malayalam_transliteration/blob/main/source_tokenizer_config.json"
|
9 |
-
target_tokenizer_config_path = "https://huggingface.co/Bajiyo/Malayalam_transliteration/blob/main/target_tokenizer_config.json"
|
10 |
|
11 |
-
# Load the
|
12 |
-
|
13 |
|
14 |
-
#
|
15 |
-
|
16 |
-
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
|
|
|
|
|
21 |
|
22 |
-
|
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 = 49 # 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()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import from_pretrained_keras
|
3 |
+
from transformers import AutoTokenizer
|
|
|
4 |
|
5 |
+
# Load the model from Hugging Face
|
6 |
+
model = from_pretrained_keras("Bajiyo/Malayalam_transliteration")
|
|
|
|
|
7 |
|
8 |
+
# Load the tokenizer
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained("Bajiyo/Malayalam_transliteration")
|
10 |
|
11 |
+
# Define a function to make predictions
|
12 |
+
def predict(text):
|
13 |
+
# Tokenize the input text
|
14 |
+
inputs = tokenizer(text, return_tensors="tf", padding=True, truncation=True)
|
15 |
|
16 |
+
# Make predictions using the model
|
17 |
+
outputs = model.predict(inputs)
|
18 |
|
19 |
+
# Decode the predicted tokens
|
20 |
+
predicted_text = tokenizer.decode(outputs.logits[0], skip_special_tokens=True)
|
21 |
|
22 |
+
return predicted_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
+
# Create a Gradio interface
|
25 |
+
inputs = gr.inputs.Textbox(label="Enter Malayalam Text")
|
26 |
+
outputs = gr.outputs.Textbox(label="Transliteration to English")
|
27 |
+
interface = gr.Interface(predict, inputs, outputs, title="Malayalam to English Transliteration")
|
28 |
interface.launch()
|