Spaces:
Runtime error
Runtime error
File size: 1,779 Bytes
429b294 ec0d22c 429b294 ec0d22c 00bedb5 ec0d22c 00bedb5 ec0d22c 4eece9c ec0d22c 4eece9c ec0d22c |
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
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):
# Return a list from tokenizer.encode instead of tensor
input_ids_list = tokenizer.encode(paragraph, max_length=1024)
# Convert the list to tensor when needed
input_ids = torch.tensor([input_ids_list])
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():
css = """
<style>
textarea {
height: 300px;
}
</style>
"""
st.markdown(css, unsafe_allow_html=True)
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() |