Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from transformers import AutoTokenizer, AutoModelForSeq2SeqLM | |
| # Load the model and tokenizer for English to Hawaiian Pidgin translation | |
| tokenizer = AutoTokenizer.from_pretrained("claudiatang/flan-t5-base-eng-hwp") | |
| model = AutoModelForSeq2SeqLM.from_pretrained("claudiatang/flan-t5-base-eng-hwp") | |
| def translate_to_hawaiian(text): | |
| # Add language direction instruction | |
| input_text = f"translate English to Hawaiian Pidgin: {text}" | |
| # Encoding the input text for the model | |
| inputs = tokenizer(input_text, return_tensors="pt", padding=True, truncation=True) | |
| # Generate translation using the model | |
| translated = model.generate(inputs["input_ids"], max_length=128, num_beams=4, early_stopping=True) | |
| # Decode the generated token IDs into a string | |
| translated_text = tokenizer.decode(translated[0], skip_special_tokens=True) | |
| return translated_text | |
| # Streamlit interface | |
| st.title("Hawaiian Pidgin Translator") | |
| st.write("This app translates English text to Hawaiian Pidgin using a language model.") | |
| # Input text from the user | |
| text_input = st.text_area("Enter text to translate:") | |
| # Translate and display the result | |
| if text_input: | |
| translation = translate_to_hawaiian(text_input) | |
| st.subheader("Translation:") | |
| st.write(translation) | |