Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,77 +1,26 @@
|
|
1 |
-
|
|
|
2 |
|
3 |
-
#
|
4 |
-
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
and returns the predictions.
|
10 |
-
"""
|
11 |
-
# Preprocess the input text (tokenization, etc.) - Implement your pre-processing logic here
|
12 |
-
processed_text = preprocess_text(text)
|
13 |
-
|
14 |
-
# Make predictions using the model
|
15 |
-
predictions = model.predict(processed_text)
|
16 |
-
|
17 |
-
# Post-process predictions (optional)
|
18 |
-
# This might involve converting probabilities to classes, decoding sequences, etc.
|
19 |
-
# Implement your post-processing logic here
|
20 |
-
processed_predictions = postprocess_predictions(predictions)
|
21 |
-
|
22 |
-
return processed_predictions
|
23 |
-
|
24 |
-
def preprocess_text(text):
|
25 |
-
"""
|
26 |
-
This function implements your specific logic for pre-processing the input text.
|
27 |
-
You'll need to replace this with your actual pre-processing steps, which might include:
|
28 |
-
|
29 |
-
- Tokenization (converting text into numerical representations)
|
30 |
-
- Padding sequences to a fixed length
|
31 |
-
- Adding special tokens (e.g., start/end of sequence)
|
32 |
-
|
33 |
-
Here's an example structure (replace with your actual implementation):
|
34 |
-
"""
|
35 |
-
# Import necessary libraries (e.g., tokenizers)
|
36 |
-
from transformers import AutoTokenizer
|
37 |
-
|
38 |
-
# Replace with your actual tokenizer name from Hugging Face Hub (if applicable)
|
39 |
-
tokenizer = AutoTokenizer.from_pretrained("Bajiyo/YourTokenizerName") # Adjust based on your model
|
40 |
-
|
41 |
-
# Tokenize the text
|
42 |
-
tokenized_text = tokenizer(text, return_tensors="tf") # Assuming TensorFlow backend
|
43 |
-
|
44 |
-
# Pad the sequence (if necessary)
|
45 |
-
# ... (implement padding logic)
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
# You can further process the predicted class index here (e.g., convert to label name)
|
64 |
-
|
65 |
-
return predicted_class
|
66 |
-
|
67 |
-
# Integrate the predict function into your Space UI (Streamlit or Gradio)
|
68 |
-
# This part will depend on the specific framework you're using (Streamlit or Gradio)
|
69 |
-
# Here's an example using Streamlit:
|
70 |
-
|
71 |
-
import streamlit as st
|
72 |
-
|
73 |
-
st.title("Malayalam Transliteration Model")
|
74 |
-
text_input = st.text_input("Enter Malayalam text to transliterate:")
|
75 |
-
if st.button("Predict"):
|
76 |
-
prediction = predict(text_input)
|
77 |
-
st.write("Transliterated English:", prediction)
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
|
4 |
+
# Model and Tokenizer Names (replace if needed)
|
5 |
+
MODEL_NAME = "Bajiyo/Malayalam_transliteration"
|
6 |
+
TOKENIZER_NAME = f"{MODEL_NAME}-vocab"
|
7 |
|
8 |
+
# Load the tokenizer and model
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained(TOKENIZER_NAME)
|
10 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
def predict(text):
|
13 |
+
input_ids = tokenizer.encode(text, return_tensors="pt")
|
14 |
+
outputs = model.generate(input_ids)
|
15 |
+
decoded_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
16 |
+
return decoded_text
|
17 |
+
|
18 |
+
interface = gr.Interface(
|
19 |
+
fn=predict,
|
20 |
+
inputs=gr.Textbox(label="Enter Malayalam Text"),
|
21 |
+
outputs=gr.Textbox(label="Predicted English Text"),
|
22 |
+
title="Malayalam to English Transliteration",
|
23 |
+
description="Enter Malayalam text in the box and click 'Predict' to get the English transliteration.",
|
24 |
+
)
|
25 |
+
|
26 |
+
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|