Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
import torch
|
4 |
|
5 |
st.title("📚 Study Buddy Chatbot")
|
@@ -23,12 +23,15 @@ def load_model():
|
|
23 |
return tokenizer, model
|
24 |
|
25 |
# Only load model when needed
|
26 |
-
if "
|
27 |
with st.spinner("Loading AI model (this may take a minute)..."):
|
28 |
-
tokenizer, model = load_model()
|
29 |
-
st.session_state.model_loaded = True
|
30 |
|
31 |
def get_response(user_input):
|
|
|
|
|
|
|
|
|
32 |
# Format conversation history for context
|
33 |
history = "\n".join(st.session_state.conversation[-6:]) # Last 6 exchanges
|
34 |
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
import torch
|
4 |
|
5 |
st.title("📚 Study Buddy Chatbot")
|
|
|
23 |
return tokenizer, model
|
24 |
|
25 |
# Only load model when needed
|
26 |
+
if "tokenizer" not in st.session_state or "model" not in st.session_state:
|
27 |
with st.spinner("Loading AI model (this may take a minute)..."):
|
28 |
+
st.session_state.tokenizer, st.session_state.model = load_model()
|
|
|
29 |
|
30 |
def get_response(user_input):
|
31 |
+
# Get tokenizer and model from session state
|
32 |
+
tokenizer = st.session_state.tokenizer
|
33 |
+
model = st.session_state.model
|
34 |
+
|
35 |
# Format conversation history for context
|
36 |
history = "\n".join(st.session_state.conversation[-6:]) # Last 6 exchanges
|
37 |
|