Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,45 +1,26 @@
|
|
1 |
-
from
|
2 |
-
import json
|
3 |
-
import gradio as gr
|
4 |
-
|
5 |
-
# Load the pre-trained Keras model (replace with actual model path if needed)
|
6 |
-
model = load_model("saved_model.pb")
|
7 |
|
8 |
# Load tokenizer configurations
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
def
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
def process_predictions(predictions, tokenizer_config):
|
31 |
-
# ... Your postprocessing steps (e.g., argmax, converting indices to tokens) ...
|
32 |
-
return decoded_text
|
33 |
-
|
34 |
-
# Create the Gradio interface
|
35 |
-
interface = gr.Interface(
|
36 |
-
fn=predict,
|
37 |
-
inputs=gr.Textbox(label="Enter Malayalam Text"),
|
38 |
-
outputs=gr.Textbox(label="Predicted English Text"),
|
39 |
-
title="Malayalam to English Transliteration",
|
40 |
-
description="Enter Malayalam text in the box and click 'Predict' to get the English transliteration.",
|
41 |
-
thumbnail="thumbnail.jpg" # Optional: Add a thumbnail image (upload to Space)
|
42 |
)
|
43 |
|
44 |
-
# Launch the interface
|
45 |
interface.launch()
|
|
|
1 |
+
from transformers import AutoTokenizer, TFBertForSeq2SeqLM # Assuming TFBert model
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
# Load tokenizer configurations
|
4 |
+
source_tokenizer = AutoTokenizer.from_pretrained("https://huggingface.co/Bajiyo/mal_en_transliteration/tree/main/source_tokenizer_config.json")
|
5 |
+
target_tokenizer = AutoTokenizer.from_pretrained("https://huggingface.co/Bajiyo/mal_en_transliteration/tree/main/target_tokenizer_config.json")
|
6 |
+
|
7 |
+
# Load the model (replace with your actual model path)
|
8 |
+
model = TFBertForSeq2SeqLM.from_pretrained("https://huggingface.co/Bajiyo/mal_en_transliteration/tree/main/transliteration_model.h5")
|
9 |
+
|
10 |
+
def translate(malayalam_text):
|
11 |
+
"""Function to perform Malayalam to English transliteration"""
|
12 |
+
source_ids = source_tokenizer(malayalam_text, return_tensors="pt")["input_ids"]
|
13 |
+
translated_tokens = model.generate(**source_ids)
|
14 |
+
english_text = target_tokenizer.batch_decode(translated_tokens, skip_special_tokens=True)[0]
|
15 |
+
return english_text
|
16 |
+
|
17 |
+
interface = gradio.Interface(
|
18 |
+
fn=translate,
|
19 |
+
inputs="text",
|
20 |
+
outputs="text",
|
21 |
+
title="Malayalam to English Transliteration",
|
22 |
+
description="Enter Malayalam text to get the English transliteration.",
|
23 |
+
examples=[["എങ്ങനെയാണ് ഞാൻ ഇംഗ്ലീഷിൽ സംസാരിക്കേണ്ടത്?"], ["ഹലോ എങ്ങനെയിരിക്കുന്നു?"]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
)
|
25 |
|
|
|
26 |
interface.launch()
|