KoQuillBot / app.py
snoop2head's picture
hotfix variable reference
db6849b
raw
history blame
1.41 kB
# -*- coding: utf-8 -*-
import numpy as np
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
st.set_page_config(page_title='KoQuillBot', layout='wide', initial_sidebar_state='expanded')
tokenizer = AutoTokenizer.from_pretrained("QuoQA-NLP/KE-T5-Ko2En-Base")
ko2en_model = AutoModelForSeq2SeqLM.from_pretrained("QuoQA-NLP/KE-T5-Ko2En-Base")
en2ko_model = AutoModelForSeq2SeqLM.from_pretrained("QuoQA-NLP/KE-T5-En2Ko-Base")
st.title("๐Ÿค– KoQuillBot")
src_text = st.text_area("๋ฐ”๊พธ๊ณ  ์‹ถ์€ ๋ฌธ์žฅ์„ ์ž…๋ ฅํ•˜์„ธ์š”:",height=None,max_chars=None,key=None,help="Enter your text here")
backtranslated = ""
if st.button('๋ฌธ์žฅ ๋ณ€ํ™˜'):
if src_text == "":
st.warning('Please **enter text** for translation')
else:
translated = ko2en_model.generate(
**tokenizer([src_text], return_tensors="pt", padding=True, max_length=64,),
max_length=64,
num_beams=5,
repetition_penalty=1.3,
no_repeat_ngram_size=3,
num_return_sequences=1,
)
backtranslated = en2ko_model.generate(
**tokenizer([translated], return_tensors="pt", padding=True, max_length=64,),
max_length=64,
num_beams=5,
repetition_penalty=1.3,
no_repeat_ngram_size=3,
num_return_sequences=1,
)
else:
pass
print(backtranslated)
st.write(backtranslated)