File size: 1,323 Bytes
813adbe
4e3d055
3b1b66f
4e3d055
 
 
0e5efd2
ce2ceca
 
4e3d055
3e088d1
ce2ceca
 
3e088d1
ce2ceca
 
3e088d1
ce2ceca
 
 
3e088d1
ce2ceca
4e3d055
 
ce2ceca
 
 
 
 
 
 
 
4e3d055
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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 (this may improve translation)
    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)