Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ from learning_platform import LearningPlatform
|
|
| 4 |
import asyncio
|
| 5 |
import nest_asyncio
|
| 6 |
from datetime import datetime
|
|
|
|
| 7 |
|
| 8 |
nest_asyncio.apply()
|
| 9 |
|
|
@@ -13,13 +14,6 @@ st.set_page_config(page_title="MicroGuru", page_icon="🎓", layout="wide")
|
|
| 13 |
# Custom CSS
|
| 14 |
st.markdown("""
|
| 15 |
<style>
|
| 16 |
-
.agent-log {
|
| 17 |
-
padding: 8px;
|
| 18 |
-
margin: 4px 0;
|
| 19 |
-
border-radius: 4px;
|
| 20 |
-
background: #f0f7ff;
|
| 21 |
-
border-left: 3px solid #1e88e5;
|
| 22 |
-
}
|
| 23 |
.module-card {
|
| 24 |
padding: 20px;
|
| 25 |
background: white;
|
|
@@ -47,13 +41,21 @@ st.markdown("""
|
|
| 47 |
</style>
|
| 48 |
""", unsafe_allow_html=True)
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
# Initialize session state
|
| 51 |
if 'learning_path' not in st.session_state:
|
| 52 |
st.session_state.learning_path = None
|
| 53 |
if 'current_module' not in st.session_state:
|
| 54 |
st.session_state.current_module = 0
|
| 55 |
-
if 'agent_logs' not in st.session_state:
|
| 56 |
-
st.session_state.agent_logs = []
|
| 57 |
if 'completed_courses' not in st.session_state:
|
| 58 |
st.session_state.completed_courses = []
|
| 59 |
if 'user_progress' not in st.session_state:
|
|
@@ -66,13 +68,6 @@ if not api_key:
|
|
| 66 |
st.stop()
|
| 67 |
platform = LearningPlatform(api_key)
|
| 68 |
|
| 69 |
-
def display_agent_logs():
|
| 70 |
-
"""Display agent activity logs in sidebar"""
|
| 71 |
-
with st.sidebar:
|
| 72 |
-
st.markdown("### 🤖 Agent Activity")
|
| 73 |
-
for log in st.session_state.agent_logs[-5:]: # Show last 5 logs
|
| 74 |
-
st.markdown(f'<div class="agent-log">{log}</div>', unsafe_allow_html=True)
|
| 75 |
-
|
| 76 |
def display_progress_bar():
|
| 77 |
"""Display course progress bar"""
|
| 78 |
if st.session_state.learning_path:
|
|
@@ -173,7 +168,6 @@ def create_new_course():
|
|
| 173 |
|
| 174 |
def main():
|
| 175 |
st.title("🎓 MicroGuru")
|
| 176 |
-
display_agent_logs()
|
| 177 |
|
| 178 |
# Navigation
|
| 179 |
pages = {
|
|
@@ -216,6 +210,10 @@ def display_current_course():
|
|
| 216 |
if path.modules[next_idx].is_complete:
|
| 217 |
if st.button("Next Module ➡️"):
|
| 218 |
st.session_state.current_module = next_idx
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
st.rerun()
|
| 220 |
else:
|
| 221 |
with st.spinner("Generating next module..."):
|
|
@@ -228,6 +226,10 @@ def display_current_course():
|
|
| 228 |
if path not in st.session_state.completed_courses:
|
| 229 |
path.completion_date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 230 |
st.session_state.completed_courses.append(path)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
|
| 232 |
|
| 233 |
def display_completed_courses():
|
|
|
|
| 4 |
import asyncio
|
| 5 |
import nest_asyncio
|
| 6 |
from datetime import datetime
|
| 7 |
+
import sqlite3
|
| 8 |
|
| 9 |
nest_asyncio.apply()
|
| 10 |
|
|
|
|
| 14 |
# Custom CSS
|
| 15 |
st.markdown("""
|
| 16 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
.module-card {
|
| 18 |
padding: 20px;
|
| 19 |
background: white;
|
|
|
|
| 41 |
</style>
|
| 42 |
""", unsafe_allow_html=True)
|
| 43 |
|
| 44 |
+
# Initialize SQLite Database
|
| 45 |
+
conn = sqlite3.connect('user_progress.db', check_same_thread=False)
|
| 46 |
+
cursor = conn.cursor()
|
| 47 |
+
cursor.execute('''CREATE TABLE IF NOT EXISTS progress (
|
| 48 |
+
user TEXT,
|
| 49 |
+
topic TEXT,
|
| 50 |
+
current_module INTEGER,
|
| 51 |
+
completion_date TEXT)''')
|
| 52 |
+
conn.commit()
|
| 53 |
+
|
| 54 |
# Initialize session state
|
| 55 |
if 'learning_path' not in st.session_state:
|
| 56 |
st.session_state.learning_path = None
|
| 57 |
if 'current_module' not in st.session_state:
|
| 58 |
st.session_state.current_module = 0
|
|
|
|
|
|
|
| 59 |
if 'completed_courses' not in st.session_state:
|
| 60 |
st.session_state.completed_courses = []
|
| 61 |
if 'user_progress' not in st.session_state:
|
|
|
|
| 68 |
st.stop()
|
| 69 |
platform = LearningPlatform(api_key)
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
def display_progress_bar():
|
| 72 |
"""Display course progress bar"""
|
| 73 |
if st.session_state.learning_path:
|
|
|
|
| 168 |
|
| 169 |
def main():
|
| 170 |
st.title("🎓 MicroGuru")
|
|
|
|
| 171 |
|
| 172 |
# Navigation
|
| 173 |
pages = {
|
|
|
|
| 210 |
if path.modules[next_idx].is_complete:
|
| 211 |
if st.button("Next Module ➡️"):
|
| 212 |
st.session_state.current_module = next_idx
|
| 213 |
+
# Save progress to DB
|
| 214 |
+
cursor.execute('''INSERT OR REPLACE INTO progress (user, topic, current_module, completion_date) VALUES (?, ?, ?, ?)''',
|
| 215 |
+
('user1', path.topic, st.session_state.current_module, None))
|
| 216 |
+
conn.commit()
|
| 217 |
st.rerun()
|
| 218 |
else:
|
| 219 |
with st.spinner("Generating next module..."):
|
|
|
|
| 226 |
if path not in st.session_state.completed_courses:
|
| 227 |
path.completion_date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 228 |
st.session_state.completed_courses.append(path)
|
| 229 |
+
# Save completion to DB
|
| 230 |
+
cursor.execute('''INSERT OR REPLACE INTO progress (user, topic, current_module, completion_date) VALUES (?, ?, ?, ?)''',
|
| 231 |
+
('user1', path.topic, len(path.modules), path.completion_date))
|
| 232 |
+
conn.commit()
|
| 233 |
|
| 234 |
|
| 235 |
def display_completed_courses():
|