Bajiyo commited on
Commit
4beb772
·
verified ·
1 Parent(s): 8d9fe38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -1,23 +1,22 @@
1
  import gradio as gr
2
- from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
 
3
 
4
- # Load your custom Hugging Face model
5
- model_name = "models/Bajiyo/Named_entity_transliteration_malayalam"
6
- model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
7
- tokenizer = AutoTokenizer.from_pretrained(model_name)
8
 
9
  # Function for transliteration
10
  def transliterate_malayalam_to_english(malayalam_text):
11
- # Tokenize the input
12
- input_ids = tokenizer.encode(malayalam_text, return_tensors="pt", max_length=50, truncation=True)
13
-
14
  # Use the model for prediction
15
- output_ids = model.generate(input_ids, max_length=49, num_beams=5)
16
 
17
- # Decode the output sequence
18
- output_sequence = tokenizer.decode(output_ids[0], skip_special_tokens=True)
19
 
20
- return output_sequence
21
 
22
  # Create a Gradio interface
23
  iface = gr.Interface(
@@ -28,4 +27,4 @@ iface = gr.Interface(
28
  )
29
 
30
  # Launch the Gradio interface
31
- iface.launch()
 
1
  import gradio as gr
2
+ from keras.models import load_model
3
+ from keras.preprocessing.sequence import pad_sequences
4
 
5
+ # Load your custom Keras model
6
+ model = load_model('/content/drive/MyDrive/best_model.h5')
 
 
7
 
8
  # Function for transliteration
9
  def transliterate_malayalam_to_english(malayalam_text):
10
+ # Tokenize and preprocess the input (adjust this based on your preprocessing logic)
11
+ input_sequence = pad_sequences(tokenizer.texts_to_sequences([malayalam_text]), maxlen=max_seq_length, padding='post')
12
+
13
  # Use the model for prediction
14
+ output_sequence = model.predict(input_sequence)
15
 
16
+ # Decode the output sequence to get the transliterated text (adjust this based on your decoding logic)
17
+ predicted_text = decode_output_sequence(output_sequence)
18
 
19
+ return predicted_text
20
 
21
  # Create a Gradio interface
22
  iface = gr.Interface(
 
27
  )
28
 
29
  # Launch the Gradio interface
30
+ iface.launch()