Update app.py
Browse files
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 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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("์ฑ์ทจ๊ธฐ์ค ๋ฐ ์ฃผ์ ๋ด์ฉ์ ์
๋ ฅํ์ธ์.")
|