ll7098ll commited on
Commit
0ba7b64
ยท
verified ยท
1 Parent(s): f1461c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -15
app.py CHANGED
@@ -5,6 +5,7 @@ import google.generativeai as genai
5
  import streamlit as st
6
  from streamlit_extras.colored_header import colored_header
7
  from streamlit_extras.add_vertical_space import add_vertical_space
 
8
 
9
  # Google Gemini API ํ‚ค ์„ค์ •
10
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
@@ -120,18 +121,33 @@ if generate_button and achievement_standard:
120
  elif generate_button and not achievement_standard:
121
  st.warning("์„ฑ์ทจ๊ธฐ์ค€ ๋ฐ ์ฃผ์š” ๋‚ด์šฉ์„ ์ž…๋ ฅํ•˜์„ธ์š”.")
122
 
123
- # ์ถœ๋ ฅ ์˜์—ญ (๋‹จ์ผ ํ…์ŠคํŠธ ์˜์—ญ, ๋ณต์‚ฌ ๋ฒ„ํŠผ ์—†์Œ)
124
- if "generated_curriculum" in st.session_state:
125
- text_area_value = st.session_state.generated_curriculum
126
-
127
- # ํ…์ŠคํŠธ ์˜์—ญ๋งŒ ํ‘œ์‹œ (์Šคํฌ๋กค ์ž๋™ ์กฐ์ •)
128
- st.markdown(
129
- """
130
- <script>
131
- const textArea = document.querySelector('.stTextArea textarea');
132
- textArea.scrollTop = textArea.scrollHeight;
133
- </script>
134
- """,
135
- unsafe_allow_html=True,
136
- )
137
- st.text_area("๊ฐœ๋…๊ธฐ๋ฐ˜ ๊ต์œก๊ณผ์ •", value=text_area_value, height=600, key="output_text_area")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  import streamlit as st
6
  from streamlit_extras.colored_header import colored_header
7
  from streamlit_extras.add_vertical_space import add_vertical_space
8
+ import streamlit.components.v1 as components
9
 
10
  # Google Gemini API ํ‚ค ์„ค์ •
11
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
 
121
  elif generate_button and not achievement_standard:
122
  st.warning("์„ฑ์ทจ๊ธฐ์ค€ ๋ฐ ์ฃผ์š” ๋‚ด์šฉ์„ ์ž…๋ ฅํ•˜์„ธ์š”.")
123
 
124
+ # ์ถœ๋ ฅ ์˜์—ญ (์ŠคํŠธ๋ฆฌ๋ฐ ์ถœ๋ ฅ ๋ฐ ์Šคํฌ๋กค ์ž๋™ ์กฐ์ •)
125
+ output_area = st.empty()
126
+ if generate_button and achievement_standard:
127
+ with output_area.container(): # ์ปจํ…Œ์ด๋„ˆ ์‚ฌ์šฉ
128
+ # ์ปดํฌ๋„ŒํŠธ ์ƒ์„ฑ ๋ฐ ์Šคํฌ๋กค ์กฐ์ • ์ฝœ๋ฐฑ ํ•จ์ˆ˜ ์ •์˜
129
+ def scroll_to_bottom():
130
+ js_code = """
131
+ <script>
132
+ const textArea = parent.document.querySelector('#output-frame .stTextArea textarea');
133
+ if (textArea) {
134
+ textArea.scrollTop = textArea.scrollHeight;
135
+ }
136
+ </script>
137
+ """
138
+ components.html(js_code, height=0, width=0)
139
+
140
+ try:
141
+ response = model.generate_content(prompt, stream=True)
142
+ full_text = ""
143
+ for chunk in response:
144
+ full_text += chunk.text
145
+ st.text_area("๊ฐœ๋…๊ธฐ๋ฐ˜ ๊ต์œก๊ณผ์ •", value=full_text, height=600, key=f"output_text_area_{time.time()}") # ๊ณ ์œ  key ๊ฐ’ ์‚ฌ์šฉ
146
+ scroll_to_bottom()
147
+ time.sleep(0.01)
148
+ st.session_state.generated_curriculum = full_text # ์„ธ์…˜ ์ƒํƒœ ์ €์žฅ
149
+ except Exception as e:
150
+ print(f"์—๋Ÿฌ ๋ฐœ์ƒ: {str(e)}")
151
+ st.error(f"์—๋Ÿฌ ๋ฐœ์ƒ: {str(e)}")
152
+ elif generate_button and not achievement_standard:
153
+ st.warning("์„ฑ์ทจ๊ธฐ์ค€ ๋ฐ ์ฃผ์š” ๋‚ด์šฉ์„ ์ž…๋ ฅํ•˜์„ธ์š”.")