File size: 2,712 Bytes
dd1981b
 
 
18ca070
dd1981b
 
 
18ca070
 
dd1981b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18ca070
dd1981b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18ca070
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import time
import os
import joblib
import streamlit as st
from utils.conceptexcerpts import concept_excerpts
from utils.exampleexcerpts import example_excerpts
from google import genai

st.set_page_config(page_title="LSAT Control - Textbook Tutor", page_icon="πŸ“˜")
st.title("πŸ“˜ LSAT Logical Reasoning - Textbook Learning (Control)")

new_chat_id = f'{time.time()}'
MODEL_ROLE = 'ai'
AI_AVATAR_ICON = '✨'

# Create a data/ folder if it doesn't already exist
try:
    os.mkdir('data/groupa')
except:
    # data/ folder already exists
    pass

# Load past chats (if available)
try:
    past_chats: dict = joblib.load('data/past_chats_list')
except:
    past_chats = {}

# Sidebar allows a list of past chats
with st.sidebar:
    st.write('# Past Chats')
    if st.session_state.get('chat_id') is None:
        st.session_state.chat_id = st.selectbox(
            label='Pick a past chat',
            options=[new_chat_id] + list(past_chats.keys()),
            format_func=lambda x: past_chats.get(x, 'New Chat'),
            placeholder='_',
        )
    else:
        # This will happen the first time AI response comes in
        st.session_state.chat_id = st.selectbox(
            label='Pick a past chat',
            options=[new_chat_id, st.session_state.chat_id] + list(past_chats.keys()),
            index=1,
            format_func=lambda x: past_chats.get(x, 'New Chat' if x != st.session_state.chat_id else st.session_state.chat_title),
            placeholder='_',
        )

    # Save new chats after a message has been sent to AI
    st.session_state.chat_title = f'ChatSession-{st.session_state.chat_id}'
    
# Chat history (allows to ask multiple questions)
try:
    st.session_state.messages = joblib.load(
        f'data/{st.session_state.chat_id}-st_messages'
    )
    st.session_state.gemini_history = joblib.load(
        f'data/{st.session_state.chat_id}-gemini_messages'
    )
except:
    st.session_state.messages = []
    st.session_state.gemini_history = []

choices = ["A", "B", "C", "D", "E"]

# Dropdown to select topic
topic = st.selectbox("Choose a topic to review:", list(concept_excerpts.keys()))

# Display Concept
st.subheader("Concept Overview")
st.markdown(concept_excerpts[topic])

# Display Question
st.subheader("Practice Question")
q = example_excerpts[topic]
st.write(q[0])
for i, choice in enumerate(choices):
    st.write(f"{i}). {choice}")

# Show answer
if st.checkbox("Show Answer"):
    st.success(f"Correct Answer: {q[1]}")

# Save to file
joblib.dump(
    st.session_state.messages,
    f'data/{st.session_state.chat_id}-st_messages',
)
joblib.dump(
    st.session_state.gemini_history,
    f'data/{st.session_state.chat_id}-gemini_messages',
)