Spaces:
Runtime error
Runtime error
updat4e application file
Browse files
app.py
CHANGED
@@ -1,4 +1,38 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|