jian1114 commited on
Commit
ec0d22c
Β·
1 Parent(s): 429b294

updat4e application file

Browse files
Files changed (1) hide show
  1. app.py +36 -2
app.py CHANGED
@@ -1,4 +1,38 @@
1
  import streamlit as st
 
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import torch
3
+ from transformers import PreTrainedTokenizerFast, BartForConditionalGeneration
4
 
5
+ model_name = 'jian1114/jian_KoBART_subheading'
6
+ tokenizer = PreTrainedTokenizerFast.from_pretrained(model_name)
7
+ model = BartForConditionalGeneration.from_pretrained(model_name)
8
+
9
+ def process_paragraph(paragraph):
10
+ input_ids = tokenizer.encode(paragraph, return_tensors='pt', max_length=1024)
11
+ output = model.generate(input_ids, max_length=32, num_beams=10, early_stopping=True)
12
+ subheading = tokenizer.decode(output[0], skip_special_tokens=True)
13
+
14
+ subheading_final = "" # μ‹€μ œ λ°˜ν™˜ν•  μ†Œμ œλͺ©
15
+ check_list = ["em class", "violet_text", "green_text", "red_text","blue_text"]
16
+ if subheading=="O" or "OO" in subheading:
17
+ subheading_final = "πŸ˜’μ†Œμ œλͺ© 생성 μ‹€νŒ¨: 더 μžμ„Έν•œ λ‚΄μš©μ΄ ν•„μš”ν•©λ‹ˆλ‹€."
18
+ elif any(x in subheading for x in check_list):
19
+ subheading_final = "πŸ˜’μ†Œμ œλͺ© 생성 μ‹€νŒ¨: 문법 ꡐ정 ν›„ λ‹€μ‹œ μ‹œλ„ν•΄ λ³΄μ„Έμš”."
20
+ else:
21
+ subheading_final = subheading
22
+
23
+ return subheading_final
24
+
25
+ def main():
26
+ st.title("Subheading Generator")
27
+ user_input = st.text_area("Enter a paragraph: ")
28
+
29
+ if st.button("Generate"):
30
+ if user_input:
31
+ with st.spinner('Generating...'):
32
+ result = process_paragraph(user_input)
33
+ st.write(f'Subheading: {result}')
34
+ else:
35
+ st.warning('Please enter a paragraph.')
36
+
37
+ if __name__ == "__main__":
38
+ main()