Update app.py
Browse files
app.py
CHANGED
@@ -24,6 +24,10 @@ topic = st.sidebar.text_input("Enter the Wikipedia topic:", "Japanese History")
|
|
24 |
model_name = 'mistralai/Mistral-7B-Instruct-v0.3'
|
25 |
HF_TOKEN = st.sidebar.text_input("Enter your Hugging Face token:", "", type="password")
|
26 |
|
|
|
|
|
|
|
|
|
27 |
# Function to validate token
|
28 |
def validate_token(token):
|
29 |
try:
|
@@ -38,9 +42,13 @@ def validate_token(token):
|
|
38 |
# Validate the token and display appropriate message
|
39 |
if HF_TOKEN:
|
40 |
if validate_token(HF_TOKEN):
|
|
|
41 |
st.sidebar.success("Token is valid!")
|
42 |
else:
|
43 |
-
st.
|
|
|
|
|
|
|
44 |
|
45 |
# Memory for chat history
|
46 |
if "history" not in st.session_state:
|
|
|
24 |
model_name = 'mistralai/Mistral-7B-Instruct-v0.3'
|
25 |
HF_TOKEN = st.sidebar.text_input("Enter your Hugging Face token:", "", type="password")
|
26 |
|
27 |
+
# Initialize session state for error message
|
28 |
+
if 'error_message' not in st.session_state:
|
29 |
+
st.session_state.error_message = ""
|
30 |
+
|
31 |
# Function to validate token
|
32 |
def validate_token(token):
|
33 |
try:
|
|
|
42 |
# Validate the token and display appropriate message
|
43 |
if HF_TOKEN:
|
44 |
if validate_token(HF_TOKEN):
|
45 |
+
st.session_state.error_message = "" # Clear error message if the token is valid
|
46 |
st.sidebar.success("Token is valid!")
|
47 |
else:
|
48 |
+
st.session_state.error_message = "Invalid token. Please try again."
|
49 |
+
st.sidebar.error(st.session_state.error_message)
|
50 |
+
elif st.session_state.error_message:
|
51 |
+
st.sidebar.error(st.session_state.error_message)
|
52 |
|
53 |
# Memory for chat history
|
54 |
if "history" not in st.session_state:
|