snoop2head's picture
initial commit
5ac8ef8
raw
history blame
1.52 kB
# -*- coding: utf-8 -*-
import numpy as np
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
st.set_page_config(
page_title="", layout="wide", initial_sidebar_state="expanded"
)
@st.cache
def load_model(model_name):
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
return model
tokenizer = AutoTokenizer.from_pretrained("snoop2head/KoBrailleT5-small-v1")
model = load_model("snoop2head/KoBrailleT5-small-v1")
st.title("ํ•œ๊ตญ์–ด ์ ์—ญ๊ณผ ์—ญ์ ์—ญ")
st.write("Braille Pattern Conversion")
default_value = '์œ„์Šคํ‚ค ๋ธŒ๋žœ๋”” ๋ธ”๋ฃจ์ง„ ํ•˜์ดํž'
src_text = st.text_area(
"๋ฒˆ์—ญํ•˜๊ณ  ์‹ถ์€ ๋ฌธ์žฅ์„ ์ž…๋ ฅํ•˜์„ธ์š”:",
default_value,
height=300,
max_chars=100,
)
print(src_text)
if src_text == "":
st.warning("Please **enter text** for translation")
else:
# translate into english sentence
translation_result = model.generate(
**tokenizer(
src_text,
return_tensors="pt",
padding="max_length",
truncation=True,
max_length=64,
),
max_length=64,
num_beams=5,
repetition_penalty=1.3,
no_repeat_ngram_size=3,
num_return_sequences=1,
)
translation_result = tokenizer.decode(
translation_result[0],
clean_up_tokenization_spaces=True,
skip_special_tokens=True,
)
print(f"{src_text} -> {translation_result}")
st.write(translation_result)
print(translation_result)