Update app.py
Browse files
app.py
CHANGED
@@ -22,13 +22,25 @@ import string
|
|
22 |
topic = st.sidebar.text_input("Enter the Wikipedia topic:", "Japanese History")
|
23 |
#query = st.sidebar.text_input("Enter your first query:", "First query")
|
24 |
model_name = 'mistralai/Mistral-7B-Instruct-v0.3'
|
25 |
-
HF_TOKEN = st.sidebar.text_input("Enter your Hugging Face token:", "
|
26 |
-
|
27 |
-
#
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
# Memory for chat history
|
34 |
if "history" not in st.session_state:
|
|
|
22 |
topic = st.sidebar.text_input("Enter the Wikipedia topic:", "Japanese History")
|
23 |
#query = st.sidebar.text_input("Enter your first query:", "First query")
|
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:
|
30 |
+
# Attempt to log in with the provided token
|
31 |
+
login(token=token)
|
32 |
+
# Check if the token is valid by trying to access some data
|
33 |
+
HfApi().whoami()
|
34 |
+
return True
|
35 |
+
except Exception as e:
|
36 |
+
return False
|
37 |
+
|
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.sidebar.error("Invalid token. Please try again.")
|
44 |
|
45 |
# Memory for chat history
|
46 |
if "history" not in st.session_state:
|