cryogenic22 commited on
Commit
b2e2a59
·
verified ·
1 Parent(s): e6ee63c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -5
app.py CHANGED
@@ -8,6 +8,7 @@ from datetime import datetime
8
  nest_asyncio.apply()
9
  st.set_page_config(page_title="MicroGuru", page_icon="🎓", layout="wide")
10
 
 
11
  if 'learning_path' not in st.session_state:
12
  st.session_state.learning_path = None
13
  if 'current_module' not in st.session_state:
@@ -81,11 +82,11 @@ def main():
81
  topic = st.text_input("What would you like to learn?")
82
  difficulty = st.selectbox("Level", ["beginner", "intermediate", "advanced"])
83
  if st.form_submit_button("Create Course 🎯"):
84
- with st.spinner('Creating your course...'):
85
  try:
86
  path = asyncio.run(platform.create_course(topic, difficulty))
87
  st.session_state.learning_path = path
88
- st.success("First module ready! Start learning while others are being prepared.")
89
  st.rerun()
90
  except Exception as e:
91
  st.error(f"Error: {str(e)}")
@@ -132,9 +133,23 @@ def main():
132
 
133
  if message := st.chat_input("Ask a question..."):
134
  st.session_state.chat_history.append({"role": "user", "content": message})
135
- with st.spinner('🤔 Thinking...'):
136
- response = "Response will be implemented here"
137
- st.session_state.chat_history.append({"role": "assistant", "content": response})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  st.rerun()
139
  else:
140
  st.info("Start a course to chat about it!")
 
8
  nest_asyncio.apply()
9
  st.set_page_config(page_title="MicroGuru", page_icon="🎓", layout="wide")
10
 
11
+ # Initialize states
12
  if 'learning_path' not in st.session_state:
13
  st.session_state.learning_path = None
14
  if 'current_module' not in st.session_state:
 
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
  path = asyncio.run(platform.create_course(topic, difficulty))
88
  st.session_state.learning_path = path
89
+ st.success("First module ready! Start learning while others generate.")
90
  st.rerun()
91
  except Exception as e:
92
  st.error(f"Error: {str(e)}")
 
133
 
134
  if message := st.chat_input("Ask a question..."):
135
  st.session_state.chat_history.append({"role": "user", "content": message})
136
+ with st.spinner('🤔 Processing...'):
137
+ current_module = st.session_state.learning_path.modules[st.session_state.current_module]
138
+ similar_content = platform.content_generator.vector_store.similarity_search(message)
139
+ context = "\n".join([doc.page_content for doc in similar_content])
140
+
141
+ crew = Crew(
142
+ agents=[platform.agents.content_creator],
143
+ tasks=[
144
+ Task(
145
+ description=f"Answer question about {message} in context of {current_module.title}",
146
+ context=context
147
+ )
148
+ ]
149
+ )
150
+ response = asyncio.run(crew.kickoff())
151
+
152
+ st.session_state.chat_history.append({"role": "assistant", "content": response['answer']})
153
  st.rerun()
154
  else:
155
  st.info("Start a course to chat about it!")