from datetime import datetime import streamlit as st from function import generate_plans, make_report, create_word_file def main(): st.title("๐Ÿฆœ๐Ÿ”— ์œค๋ฆฌ ๋ณด๊ณ ์„œ ์ƒ์„ฑ") # ์„ธ์…˜ ์ƒํƒœ์—์„œ topics์™€ word_file ์ดˆ๊ธฐํ™” if 'topics' not in st.session_state: st.session_state.topics = {} if 'word_file' not in st.session_state: st.session_state.word_file = None with st.form("my_form_1"): text = st.text_area( "์œค๋ฆฌ ์†Œ์žฌ ์ž…๋ ฅ:", "๋ฌด์—‡๊ณผ ๊ด€๋ จ๋œ ์ฃผ์ œ๋ฅผ ์ƒ์„ฑํ• ๊นŒ์š”?", ) submitted = st.form_submit_button("์ฃผ์ œ ์ƒ์„ฑ") if submitted: # ๋กœ๋”ฉ ์• ๋‹ˆ๋ฉ”์ด์…˜๊ณผ ๋ฉ”์‹œ์ง€ ํ‘œ์‹œ with st.spinner('์•ฝ 30์ดˆ ์ •๋„ ์†Œ์š”๋ฉ๋‹ˆ๋‹ค...'): response = generate_plans(text) # ์‹ค์ œ๋กœ๋Š” ์ด ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ response ์ƒ์„ฑ # ๊ธฐ์กด topics๋ฅผ ์ดˆ๊ธฐํ™”ํ•˜๊ณ  ์ƒˆ๋กœ์šด ์ฃผ์ œ์™€ ์„ค๋ช…์„ ์„ธ์…˜ ์ƒํƒœ์— ์ €์žฅ st.session_state.topics = {} for i in range(1, 9): topic, description = response[str(i)].split(": ", 1) st.session_state.topics[topic] = description # ๊ฐ ์ฃผ์ œ๋ฅผ ์ถœ๋ ฅ for key, value in response.items(): topic, description = value.split(": ", 1) st.markdown(f"#### ์ฃผ์ œ {key}: {topic}") st.write(f"**์ƒ์„ธ ์„ค๋ช…**: {description}") st.markdown("---") # ์ฃผ์ œ ๊ฐ„ ๊ตฌ๋ถ„์„  ์ถ”๊ฐ€ # ๋‘ ๋ฒˆ์งธ ํผ (์ฃผ์ œ ์„ ํƒ) if st.session_state.topics: # topics๊ฐ€ ์„ธ์…˜์— ์ €์žฅ๋œ ๊ฒฝ์šฐ๋งŒ ์‹คํ–‰ with st.form("my_form_2"): ์ฃผ์ œ = st.radio( '์–ด๋–ค ์ฃผ์ œ๋กœ ๊ฐœ์š”๋ฅผ ์ƒ์„ฑํ• ๊นŒ์š”?', list(st.session_state.topics.keys()), index=0 ) submitted = st.form_submit_button("๋ณด๊ณ ์„œ ์ƒ์„ฑ") if submitted: # ๋กœ๋”ฉ ์• ๋‹ˆ๋ฉ”์ด์…˜๊ณผ ๋ฉ”์‹œ์ง€ ํ‘œ์‹œ with st.spinner('์•ฝ 2๋ถ„ ์ •๋„ ์†Œ์š”๋ฉ๋‹ˆ๋‹ค...'): text = f"{์ฃผ์ œ} : {st.session_state.topics[์ฃผ์ œ]}" response2 = make_report(text) st.code(response2, language='markdown') st.markdown("---") st.info(f"๋ณด๊ณ ์„œ ์ƒ์„ฑ ์‹œ๊ฐ : {datetime.now().strftime('%Y-%m-%d %H:%M')}") # ์›Œ๋“œ ํŒŒ์ผ ์ƒ์„ฑ st.session_state.word_file = create_word_file(response2) # ํผ ์™ธ๋ถ€์—์„œ ๋‹ค์šด๋กœ๋“œ ๋ฒ„ํŠผ ํ‘œ์‹œ if st.session_state.word_file: st.download_button( label="์›Œ๋“œ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ", data=st.session_state.word_file, file_name="report.docx", mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document" ) else: st.write("๋ณด๊ณ ์„œ๋ฅผ ์ƒ์„ฑํ•œ ํ›„์— ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.") if __name__ == "__main__": main()