Spaces:
Sleeping
Sleeping
Commit
·
ebf5b35
1
Parent(s):
a0077c1
优化加载图标
Browse files
app.py
CHANGED
|
@@ -209,24 +209,21 @@ def decorate_user_question(user_question, retrieved_chunks_for_user):
|
|
| 209 |
@st.cache_data
|
| 210 |
def initialize_app(added_files, num_lessons, language):
|
| 211 |
temp_file_paths = []
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
embeddings_df, faiss_index = constructVDB(temp_file_paths)
|
| 224 |
-
vdb_state.text("Constructing vector database from provided materials...Done")
|
| 225 |
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
outline_generating_state.text("Generating Course Outline...Done")
|
| 230 |
|
| 231 |
outline_presenting = st.empty()
|
| 232 |
course_outline_string = ''
|
|
@@ -239,25 +236,20 @@ def initialize_app(added_files, num_lessons, language):
|
|
| 239 |
st.write(course_outline_string)
|
| 240 |
|
| 241 |
content_presenting = st.empty()
|
| 242 |
-
content_generating_state = st.empty()
|
| 243 |
count_generating_content = 0
|
| 244 |
course_content_list = []
|
| 245 |
for lesson in course_outline_list:
|
| 246 |
count_generating_content += 1
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
with content_presenting.expander(f"Learn the lesson {count_generating_content} ", expanded=False):
|
| 253 |
st.markdown(courseContent)
|
| 254 |
|
| 255 |
-
file_proc_state.empty()
|
| 256 |
-
vdb_state.empty()
|
| 257 |
-
outline_generating_state.empty()
|
| 258 |
outline_presenting.empty()
|
| 259 |
content_presenting.empty()
|
| 260 |
-
content_generating_state.empty()
|
| 261 |
|
| 262 |
return embeddings_df, faiss_index, course_outline_list, course_content_list
|
| 263 |
|
|
|
|
| 209 |
@st.cache_data
|
| 210 |
def initialize_app(added_files, num_lessons, language):
|
| 211 |
temp_file_paths = []
|
| 212 |
+
with st.spinner('Processing file...'):
|
| 213 |
+
for added_file in added_files:
|
| 214 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".md") as tmp:
|
| 215 |
+
tmp.write(added_file.getvalue())
|
| 216 |
+
tmp_path = tmp.name
|
| 217 |
+
temp_file_paths.append(tmp_path)
|
| 218 |
+
st.success('Processing file...Done!')
|
| 219 |
+
|
| 220 |
+
with st.spinner('Constructing vector database from provided materials...'):
|
| 221 |
+
embeddings_df, faiss_index = constructVDB(temp_file_paths)
|
| 222 |
+
st.success("Constructing vector database from provided materials...Done")
|
|
|
|
|
|
|
| 223 |
|
| 224 |
+
with st.spinner('Generating Course Outline...'):
|
| 225 |
+
course_outline_list = courseOutlineGenerating(temp_file_paths, num_lessons, language)
|
| 226 |
+
st.success("Generating Course Outline...Done")
|
|
|
|
| 227 |
|
| 228 |
outline_presenting = st.empty()
|
| 229 |
course_outline_string = ''
|
|
|
|
| 236 |
st.write(course_outline_string)
|
| 237 |
|
| 238 |
content_presenting = st.empty()
|
|
|
|
| 239 |
count_generating_content = 0
|
| 240 |
course_content_list = []
|
| 241 |
for lesson in course_outline_list:
|
| 242 |
count_generating_content += 1
|
| 243 |
+
with st.spinner(f"Writing content for lesson {count_generating_content}..."):
|
| 244 |
+
retrievedChunksList = searchVDB(lesson, st.session_state.embeddings_df, st.session_state.faiss_index)
|
| 245 |
+
courseContent = generateCourse(lesson, retrievedChunksList, language)
|
| 246 |
+
course_content_list.append(courseContent)
|
| 247 |
+
st.success(f"Writing content for lesson {count_generating_content}...Done")
|
| 248 |
with content_presenting.expander(f"Learn the lesson {count_generating_content} ", expanded=False):
|
| 249 |
st.markdown(courseContent)
|
| 250 |
|
|
|
|
|
|
|
|
|
|
| 251 |
outline_presenting.empty()
|
| 252 |
content_presenting.empty()
|
|
|
|
| 253 |
|
| 254 |
return embeddings_df, faiss_index, course_outline_list, course_content_list
|
| 255 |
|