Spaces:
Running
Running
Commit
·
848b83c
1
Parent(s):
8fb7910
加入课程风格选择
Browse files
app.py
CHANGED
@@ -134,7 +134,6 @@ def constructVDB(file_paths):
|
|
134 |
#从embeddings到向量数据库
|
135 |
# Load the embeddings
|
136 |
embeddings = paraphrase_embeddings_df.iloc[:, 1:].values # All columns except the first (chunk text)
|
137 |
-
|
138 |
# Ensure that the array is C-contiguous
|
139 |
embeddings = np.ascontiguousarray(embeddings, dtype=np.float32)
|
140 |
# Preparation for Faiss
|
@@ -171,7 +170,7 @@ def searchVDB(search_sentence, paraphrase_embeddings_df, index):
|
|
171 |
|
172 |
return retrieved_chunks_list
|
173 |
|
174 |
-
def generateCourse(topic, materials, language):
|
175 |
#调用gpt4 API生成一节课的内容
|
176 |
system_message = 'You are a great AI teacher and linguist, skilled at writing informative and easy-to-understand course script based on given lesson topic and knowledge materials.'
|
177 |
|
@@ -189,6 +188,7 @@ def generateCourse(topic, materials, language):
|
|
189 |
lesson topic and abstract: 「{topic}」,
|
190 |
knowledge materials related to this lesson:【{materials} 】
|
191 |
the script should be witten in {language}, and mathematical symbols should be written in markdown form.
|
|
|
192 |
Start writting the script of this lesson now.
|
193 |
"""
|
194 |
|
@@ -289,6 +289,22 @@ def regenerate_content(course_content_list):
|
|
289 |
except Exception:
|
290 |
pass
|
291 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
def app():
|
293 |
st.title("OmniTutor v0.1.0")
|
294 |
st.markdown("""
|
@@ -308,13 +324,20 @@ def app():
|
|
308 |
""", unsafe_allow_html=True)
|
309 |
with st.sidebar:
|
310 |
st.image("https://siyuan-harry.oss-cn-beijing.aliyuncs.com/oss://siyuan-harry/20231021212525.png")
|
311 |
-
added_files = st.file_uploader('Upload .md
|
312 |
with st.expander('Customize my course'):
|
313 |
num_lessons = st.slider('How many lessons do you want this course to have?', min_value=2, max_value=15, value=5, step=1)
|
314 |
language = 'English'
|
315 |
Chinese = st.checkbox('Output in Chinese')
|
316 |
-
|
317 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
318 |
btn = st.button('Generate my course!')
|
319 |
|
320 |
if "description1" not in st.session_state:
|
@@ -360,11 +383,11 @@ def app():
|
|
360 |
#initialize app
|
361 |
temp_file_paths = initialize_file(added_files)
|
362 |
st.session_state.embeddings_df, st.session_state.faiss_index = initialize_vdb(temp_file_paths)
|
363 |
-
st.session_state.course_outline_list = initialize_outline(temp_file_paths, num_lessons, language)
|
364 |
st.session_state.course_content_list = initialize_content(st.session_state.course_outline_list, st.session_state.embeddings_df, st.session_state.faiss_index, language)
|
365 |
|
366 |
st.markdown('''
|
367 |
-
> 🤔 <font color = 'grey'> Not satisfied with this course
|
368 |
>
|
369 |
> 😁 <font color = 'grey'> If the course is good enough for you, learn and enter questions related in the input box below 👇... </font>
|
370 |
|
@@ -406,7 +429,7 @@ def app():
|
|
406 |
retrieved_chunks_for_user = searchVDB(user_question, st.session_state.embeddings_df, st.session_state.faiss_index)
|
407 |
prompt = decorate_user_question(user_question, retrieved_chunks_for_user)
|
408 |
st.session_state.messages.append({"role": "user", "content": [user_question, prompt]})
|
409 |
-
|
410 |
# Display assistant response in chat message container
|
411 |
with st.chat_message("assistant"):
|
412 |
message_placeholder = st.empty()
|
@@ -422,6 +445,5 @@ def app():
|
|
422 |
st.session_state.messages.append({"role": "assistant", "content": [full_response,1]})
|
423 |
|
424 |
|
425 |
-
|
426 |
if __name__ == "__main__":
|
427 |
app()
|
|
|
134 |
#从embeddings到向量数据库
|
135 |
# Load the embeddings
|
136 |
embeddings = paraphrase_embeddings_df.iloc[:, 1:].values # All columns except the first (chunk text)
|
|
|
137 |
# Ensure that the array is C-contiguous
|
138 |
embeddings = np.ascontiguousarray(embeddings, dtype=np.float32)
|
139 |
# Preparation for Faiss
|
|
|
170 |
|
171 |
return retrieved_chunks_list
|
172 |
|
173 |
+
def generateCourse(topic, materials, language, style_options):
|
174 |
#调用gpt4 API生成一节课的内容
|
175 |
system_message = 'You are a great AI teacher and linguist, skilled at writing informative and easy-to-understand course script based on given lesson topic and knowledge materials.'
|
176 |
|
|
|
188 |
lesson topic and abstract: 「{topic}」,
|
189 |
knowledge materials related to this lesson:【{materials} 】
|
190 |
the script should be witten in {language}, and mathematical symbols should be written in markdown form.
|
191 |
+
{style_options}
|
192 |
Start writting the script of this lesson now.
|
193 |
"""
|
194 |
|
|
|
289 |
except Exception:
|
290 |
pass
|
291 |
|
292 |
+
def add_prompt_course_style(selected_style_list):
|
293 |
+
initiate_prompt = 'Please be siginificantly aware that this course is requested to: \n'
|
294 |
+
if len(selected_style_list) != 0:
|
295 |
+
customize_prompt += initiate_prompt
|
296 |
+
for style in selected_style_list:
|
297 |
+
if style == "More examples":
|
298 |
+
customize_prompt += '- **contain more examples**. You should use your own knowledge to vividly exemplify key concepts occured in this course.\n'
|
299 |
+
elif style == "More excercises":
|
300 |
+
customize_prompt += '- **contain more excercises**. So last part of this lesson should be excercises.\n'
|
301 |
+
elif style == "Easier to learn":
|
302 |
+
customize_prompt += '- **Be easier to learn**. So you should use plain language to write the lesson script, and apply some metaphors & analogys wherever appropriate.\n'
|
303 |
+
else:
|
304 |
+
customize_prompt = ''
|
305 |
+
|
306 |
+
return customize_prompt
|
307 |
+
|
308 |
def app():
|
309 |
st.title("OmniTutor v0.1.0")
|
310 |
st.markdown("""
|
|
|
324 |
""", unsafe_allow_html=True)
|
325 |
with st.sidebar:
|
326 |
st.image("https://siyuan-harry.oss-cn-beijing.aliyuncs.com/oss://siyuan-harry/20231021212525.png")
|
327 |
+
added_files = st.file_uploader('Upload .md or .pdf files, simultaneous mixed upload these types is supported.', type=['.md','.pdf'], accept_multiple_files=True)
|
328 |
with st.expander('Customize my course'):
|
329 |
num_lessons = st.slider('How many lessons do you want this course to have?', min_value=2, max_value=15, value=5, step=1)
|
330 |
language = 'English'
|
331 |
Chinese = st.checkbox('Output in Chinese')
|
332 |
+
if Chinese:
|
333 |
+
language = 'Chinese'
|
334 |
+
custom_options = st.multiselect(
|
335 |
+
'Customize ',
|
336 |
+
['More examples', 'More excercises', 'Easier to learn'],
|
337 |
+
max_selections = 2
|
338 |
+
)
|
339 |
+
style_options = add_prompt_course_style(custom_options)
|
340 |
+
|
341 |
btn = st.button('Generate my course!')
|
342 |
|
343 |
if "description1" not in st.session_state:
|
|
|
383 |
#initialize app
|
384 |
temp_file_paths = initialize_file(added_files)
|
385 |
st.session_state.embeddings_df, st.session_state.faiss_index = initialize_vdb(temp_file_paths)
|
386 |
+
st.session_state.course_outline_list = initialize_outline(temp_file_paths, num_lessons, language, style_options)
|
387 |
st.session_state.course_content_list = initialize_content(st.session_state.course_outline_list, st.session_state.embeddings_df, st.session_state.faiss_index, language)
|
388 |
|
389 |
st.markdown('''
|
390 |
+
> 🤔 <font color = 'grey'> **Not satisfied with this course?** Simply click "Generate my course!" button to regenerate a new one! </font>
|
391 |
>
|
392 |
> 😁 <font color = 'grey'> If the course is good enough for you, learn and enter questions related in the input box below 👇... </font>
|
393 |
|
|
|
429 |
retrieved_chunks_for_user = searchVDB(user_question, st.session_state.embeddings_df, st.session_state.faiss_index)
|
430 |
prompt = decorate_user_question(user_question, retrieved_chunks_for_user)
|
431 |
st.session_state.messages.append({"role": "user", "content": [user_question, prompt]})
|
432 |
+
|
433 |
# Display assistant response in chat message container
|
434 |
with st.chat_message("assistant"):
|
435 |
message_placeholder = st.empty()
|
|
|
445 |
st.session_state.messages.append({"role": "assistant", "content": [full_response,1]})
|
446 |
|
447 |
|
|
|
448 |
if __name__ == "__main__":
|
449 |
app()
|