cryogenic22 commited on
Commit
3fd8a45
Β·
verified Β·
1 Parent(s): e2dac0a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -85
app.py CHANGED
@@ -75,94 +75,53 @@ def main():
75
 
76
  tabs = st.tabs(["🏠 Learn", "πŸ’¬ Chat", "πŸ“š My Courses"])
77
 
78
-
79
- with tabs[0]:
80
- if not st.session_state.learning_path:
81
- st.markdown("### πŸš€ Start Learning")
82
- with st.form("course_generator"):
83
- topic = st.text_input("What would you like to learn?")
84
- difficulty = st.selectbox("Level", ["beginner", "intermediate", "advanced"])
85
- if st.form_submit_button("Create Course 🎯"):
86
- with st.spinner('Creating your personalized course...'):
87
- try:
88
- async def create_and_set_course():
89
- path = await platform.create_course(topic, difficulty)
90
- st.session_state.learning_path = path
91
- return path
92
- path = asyncio.run(create_and_set_course())
93
- st.success("First module ready! Start learning while others generate.")
94
- st.rerun()
95
- except Exception as e:
96
- st.error(f"Error: {str(e)}")
97
- else:
98
- path = st.session_state.learning_path
99
- current_module = path.modules[st.session_state.current_module]
100
-
101
- st.markdown(f"### πŸ“š {current_module.title}")
102
-
103
- if not current_module.is_complete:
104
- st.info("πŸ”„ Module content is being generated...")
105
- st.spinner("Please wait...")
106
  else:
107
- for section in current_module.sections:
108
- display_section(section)
109
-
110
- col1, col2 = st.columns(2)
111
- with col1:
112
- if st.session_state.current_module > 0:
113
- if st.button("⬅️ Previous Module"):
114
- st.session_state.current_module -= 1
115
- st.rerun()
116
-
117
- with col2:
118
- next_idx = st.session_state.current_module + 1
119
- if next_idx < len(path.modules):
120
- if path.modules[next_idx].is_complete:
121
- if st.button("Next Module ➑️"):
122
- st.session_state.current_module = next_idx
123
- st.rerun()
124
- else:
125
- st.info("⏳ Next module is being prepared...")
126
-
127
-
128
- with tabs[1]:
129
- if st.session_state.learning_path:
130
- st.markdown("### πŸ’¬ Chat with MicroGuru")
131
 
132
- for msg in st.session_state.chat_history:
133
- st.markdown(f'''
134
- <div class="chat-message {'user-message' if msg['role'] == 'user' else 'assistant-message'}">
135
- {msg['content']}
136
- </div>
137
- ''', unsafe_allow_html=True)
138
 
139
- if message := st.chat_input("Ask a question..."):
140
- st.session_state.chat_history.append({"role": "user", "content": message})
141
- with st.spinner('πŸ€” Processing...'):
142
- current_module = st.session_state.learning_path.modules[st.session_state.current_module]
143
- similar_content = platform.content_generator.vector_store.similarity_search(message)
144
- context = "\n".join([doc.page_content for doc in similar_content])
145
-
146
- crew = Crew(
147
- agents=[platform.agents.content_creator],
148
- tasks=[
149
- Task(
150
- description=f"Answer question about {message} in context of {current_module.title}",
151
- context=context
152
- )
153
- ]
154
- )
155
- response = asyncio.run(crew.kickoff())
156
-
157
- st.session_state.chat_history.append({"role": "assistant", "content": response['answer']})
158
- st.rerun()
159
- else:
160
- st.info("Start a course to chat about it!")
161
-
162
- with tabs[2]:
163
- st.markdown("### My Learning Journey")
164
- if not st.session_state.courses['in_progress']:
165
- st.info("No courses yet. Start learning!")
166
 
167
  if __name__ == "__main__":
168
  main()
 
75
 
76
  tabs = st.tabs(["🏠 Learn", "πŸ’¬ Chat", "πŸ“š My Courses"])
77
 
78
+ with tabs[0]:
79
+ if not st.session_state.learning_path:
80
+ st.markdown("### πŸš€ Start Learning")
81
+ with st.form("course_generator"):
82
+ topic = st.text_input("What would you like to learn?")
83
+ difficulty = st.selectbox("Level", ["beginner", "intermediate", "advanced"])
84
+ if st.form_submit_button("Create Course 🎯"):
85
+ with st.spinner('Creating your personalized course...'):
86
+ try:
87
+ async def create_and_set_course():
88
+ path = await platform.create_course(topic, difficulty)
89
+ st.session_state.learning_path = path
90
+ return path
91
+ path = asyncio.run(create_and_set_course())
92
+ st.success("First module ready! Start learning while others generate.")
93
+ st.rerun()
94
+ except Exception as e:
95
+ st.error(f"Error: {str(e)}")
 
 
 
 
 
 
 
 
 
 
96
  else:
97
+ path = st.session_state.learning_path
98
+ current_module = path.modules[st.session_state.current_module]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
 
100
+ st.markdown(f"### πŸ“š {current_module.title}")
 
 
 
 
 
101
 
102
+ if not current_module.is_complete:
103
+ st.info("πŸ”„ Module content is being generated...")
104
+ st.spinner("Please wait...")
105
+ else:
106
+ for section in current_module.sections:
107
+ display_section(section)
108
+
109
+ col1, col2 = st.columns(2)
110
+ with col1:
111
+ if st.session_state.current_module > 0:
112
+ if st.button("⬅️ Previous Module"):
113
+ st.session_state.current_module -= 1
114
+ st.rerun()
115
+
116
+ with col2:
117
+ next_idx = st.session_state.current_module + 1
118
+ if next_idx < len(path.modules):
119
+ if path.modules[next_idx].is_complete:
120
+ if st.button("Next Module ➑️"):
121
+ st.session_state.current_module = next_idx
122
+ st.rerun()
123
+ else:
124
+ st.info("⏳ Next module is being prepared...")
 
 
 
 
125
 
126
  if __name__ == "__main__":
127
  main()