jian1114's picture
updat4e application file
ec0d22c
raw
history blame
1.5 kB
import streamlit as st
import torch
from transformers import PreTrainedTokenizerFast, BartForConditionalGeneration
model_name = 'jian1114/jian_KoBART_subheading'
tokenizer = PreTrainedTokenizerFast.from_pretrained(model_name)
model = BartForConditionalGeneration.from_pretrained(model_name)
def process_paragraph(paragraph):
input_ids = tokenizer.encode(paragraph, return_tensors='pt', max_length=1024)
output = model.generate(input_ids, max_length=32, num_beams=10, early_stopping=True)
subheading = tokenizer.decode(output[0], skip_special_tokens=True)
subheading_final = "" # μ‹€μ œ λ°˜ν™˜ν•  μ†Œμ œλͺ©
check_list = ["em class", "violet_text", "green_text", "red_text","blue_text"]
if subheading=="O" or "OO" in subheading:
subheading_final = "πŸ˜’μ†Œμ œλͺ© 생성 μ‹€νŒ¨: 더 μžμ„Έν•œ λ‚΄μš©μ΄ ν•„μš”ν•©λ‹ˆλ‹€."
elif any(x in subheading for x in check_list):
subheading_final = "πŸ˜’μ†Œμ œλͺ© 생성 μ‹€νŒ¨: 문법 ꡐ정 ν›„ λ‹€μ‹œ μ‹œλ„ν•΄ λ³΄μ„Έμš”."
else:
subheading_final = subheading
return subheading_final
def main():
st.title("Subheading Generator")
user_input = st.text_area("Enter a paragraph: ")
if st.button("Generate"):
if user_input:
with st.spinner('Generating...'):
result = process_paragraph(user_input)
st.write(f'Subheading: {result}')
else:
st.warning('Please enter a paragraph.')
if __name__ == "__main__":
main()