Update app.py
Browse files
app.py
CHANGED
@@ -12,33 +12,29 @@ st.subheader("Let's create fun and imaginative stories together!")
|
|
12 |
level = st.selectbox("Choose your level:", ["Beginner", "Intermediate", "Advanced"])
|
13 |
|
14 |
# ปุ่มเริ่มต้น
|
|
|
|
|
|
|
15 |
start_button = st.button("Start Creating Your Story!")
|
16 |
|
17 |
# ตรวจสอบเมื่อกดปุ่มเริ่มต้น
|
18 |
-
# การเช็คและบันทึกค่าใน session_state
|
19 |
if start_button:
|
20 |
st.session_state["level"] = level # บันทึกระดับที่เลือกไว้ใน session
|
21 |
-
st.session_state["story_started"] = True #
|
22 |
-
# เช็คว่าค่าใน session_state ถูกบันทึกแล้ว ก่อนเรียก experimental_rerun
|
23 |
-
if st.session_state.get("story_started"):
|
24 |
-
st.experimental_rerun() # รีเฟรชหน้าเพื่อลงไปยังส่วนการแต่งเรื่อง
|
25 |
-
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
if st.session_state.get("story_started"):
|
30 |
st.header("JoyStory - Let's Create!")
|
31 |
|
32 |
-
#
|
33 |
if "story_text" not in st.session_state:
|
34 |
st.session_state["story_text"] = "Once upon a time, in a magical forest..."
|
35 |
|
36 |
st.write(st.session_state["story_text"])
|
37 |
|
38 |
-
#
|
39 |
user_input = st.text_input("Add your sentence:")
|
40 |
if st.button("Submit"):
|
41 |
-
# ประมวลผลเพื่อให้ AI เพิ่มประโยคต่อจากที่เด็กเขียน
|
42 |
response = openai.Completion.create(
|
43 |
model="text-davinci-003",
|
44 |
prompt=st.session_state["story_text"] + " " + user_input,
|
@@ -48,5 +44,4 @@ if st.session_state.get("story_started"):
|
|
48 |
|
49 |
# อัปเดตเรื่องราวที่กำลังดำเนินอยู่
|
50 |
st.session_state["story_text"] += " " + user_input + " " + ai_text
|
51 |
-
st.
|
52 |
-
|
|
|
12 |
level = st.selectbox("Choose your level:", ["Beginner", "Intermediate", "Advanced"])
|
13 |
|
14 |
# ปุ่มเริ่มต้น
|
15 |
+
if "story_started" not in st.session_state:
|
16 |
+
st.session_state["story_started"] = False # กำหนดค่าเริ่มต้น
|
17 |
+
|
18 |
start_button = st.button("Start Creating Your Story!")
|
19 |
|
20 |
# ตรวจสอบเมื่อกดปุ่มเริ่มต้น
|
|
|
21 |
if start_button:
|
22 |
st.session_state["level"] = level # บันทึกระดับที่เลือกไว้ใน session
|
23 |
+
st.session_state["story_started"] = True # เปลี่ยนสถานะการเริ่มเรื่อง
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
# เมื่อการแต่งเรื่องเริ่มต้นแล้ว
|
26 |
+
if st.session_state["story_started"]:
|
|
|
27 |
st.header("JoyStory - Let's Create!")
|
28 |
|
29 |
+
# เริ่มต้นเนื้อเรื่อง
|
30 |
if "story_text" not in st.session_state:
|
31 |
st.session_state["story_text"] = "Once upon a time, in a magical forest..."
|
32 |
|
33 |
st.write(st.session_state["story_text"])
|
34 |
|
35 |
+
# กล่องให้เด็กแต่งประโยค
|
36 |
user_input = st.text_input("Add your sentence:")
|
37 |
if st.button("Submit"):
|
|
|
38 |
response = openai.Completion.create(
|
39 |
model="text-davinci-003",
|
40 |
prompt=st.session_state["story_text"] + " " + user_input,
|
|
|
44 |
|
45 |
# อัปเดตเรื่องราวที่กำลังดำเนินอยู่
|
46 |
st.session_state["story_text"] += " " + user_input + " " + ai_text
|
47 |
+
st.write(st.session_state["story_text"])
|
|