Spaces:
Sleeping
Sleeping
File size: 6,683 Bytes
7d04776 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
import streamlit as st
from streamlit_extras.switch_page_button import switch_page
import time
import streamlit.components.v1 as components
from st_pages import Page, Section, show_pages, add_indentation
import shutil
import os
try:
from pages.step2 import generate_course_section
except ImportError:
from step2 import generate_course_section
add_indentation()
def clear_generation_cache():
"""clear the session state for generated course sections"""
generation_keys = ['generated_course_1', 'generated_course_2', 'generated_course_3', 'generated_course_4']
for key in generation_keys:
if key in st.session_state:
del st.session_state[key]
def main():
st.header("๐ Generating Your Customized Course")
if hasattr(st.session_state, 'paper_category'):
category_display = {
"EDUCATION_LEARNING_SCIENCE": "Education/Learning Science",
"LINGUISTICS_THEORY": "Linguistics/Theory (Generating general language tutoring course)",
"NON_EDUCATION": "Non-Education Field (Generating general tutoring strategies)"
}
st.info(f"๐ Paper Classification: {category_display.get(st.session_state.paper_category, 'Unknown')}")
required_keys = ['key', 'text', 'template1', 'topic']
missing_keys = [key for key in required_keys if key not in st.session_state]
if missing_keys:
st.error(f"โ Missing required data: {missing_keys}")
st.warning("Please go back and complete the setup process.")
col1, col2 = st.columns([1, 1])
with col1:
if st.button("๐ Go to Home"):
switch_page("app")
with col2:
if st.button("๐ Go to Step 2"):
switch_page("step2")
return
with st.expander("๐ Current Configuration", expanded=False):
st.write(f"**Topic:** {st.session_state.get('topic', 'Not set')}")
st.write(f"**Learning Objective:** {st.session_state.get('learning_objective', 'Default objectives will be used')}")
st.write(f"**Template Type:** {'Math Content' if st.session_state.get('is_math_template', False) else 'General Tutoring'}")
st.write(f"**Text Chunks:** {len(st.session_state.get('text', []))} chunks loaded")
clear_generation_cache()
if not st.session_state.get('generated_course_1'):
progress_bar = st.progress(0)
status_text = st.empty()
try:
status_text.text("๐ Generating Course Introduction...")
progress_bar.progress(10)
template1 = st.session_state.template1
if '{learning_objective}' in template1:
formatted_template = template1.format(
learning_objective=st.session_state.get('learning_objective', 'Develop effective tutoring strategies')
)
else:
formatted_template = template1
st.session_state.generated_course_1 = generate_course_section(
st.session_state.key,
st.session_state.text,
formatted_template
)
progress_bar.progress(30)
# Scenario 1
status_text.text("๐ Generating Scenario 1...")
st.session_state.generated_course_2 = generate_course_section(
st.session_state.key,
st.session_state.text,
st.session_state.template2
)
progress_bar.progress(60)
# Scenario 2
status_text.text("๐ Generating Scenario 2...")
st.session_state.generated_course_3 = generate_course_section(
st.session_state.key,
st.session_state.text,
st.session_state.template3
)
progress_bar.progress(85)
# Research Insights
status_text.text("๐ Generating Research Insights...")
st.session_state.generated_course_4 = generate_course_section(
st.session_state.key,
st.session_state.text,
st.session_state.template4
)
progress_bar.progress(100)
status_text.text("โ
Course generation completed!")
time.sleep(1)
progress_bar.empty()
status_text.empty()
except Exception as e:
st.error(f"โ Error generating course: {str(e)}")
st.write("Please try again or check your settings.")
col1, col2 = st.columns([1, 1])
with col1:
if st.button("๐ Retry Generation"):
clear_generation_cache()
st.rerun()
with col2:
if st.button("๐ Go Back to Home"):
switch_page("app")
return
st.success("๐ Course Generated Successfully!")
with st.container():
st.markdown("### ๐ Course Introduction")
if st.session_state.get('generated_course_1'):
st.write(st.session_state.generated_course_1)
else:
st.warning("Course introduction not available")
st.markdown("---")
col1, col2, col3 = st.columns([2, 2, 2])
with col1:
if st.button("โฌ
๏ธ Previous", help="Go back to setup"):
switch_page("step2")
with col2:
if st.button("๐ Regenerate", help="Generate new content", key="regenerate_results"):
clear_generation_cache()
# ๆธ
็ๅ้ๆฐๆฎๅบ
for item in os.listdir("."):
if item.startswith("chroma_db"):
try:
shutil.rmtree(item, ignore_errors=True)
except:
pass
st.rerun()
with col3:
if st.button("โก๏ธ Next", help="Go to Scenario 1"):
switch_page("page 2: scenario 1")
st.markdown("---")
st.markdown("### ๐ Quick Navigation")
nav_col1, nav_col2, nav_col3, nav_col4 = st.columns(4)
with nav_col1:
if st.button("๐ Introduction", key="nav1"):
switch_page("Page 1: Introduction")
with nav_col2:
if st.button("๐ญ Scenario 1", key="nav2"):
switch_page("page 2: scenario 1")
with nav_col3:
if st.button("๐ช Scenario 2", key="nav3"):
switch_page("Page 3: Scenario 2")
with nav_col4:
if st.button("๐ฌ Research", key="nav4"):
switch_page("Page 4: Research Says")
if __name__ == "__main__":
main() |