Ryu-m0m commited on
Commit
d75a007
1 Parent(s): 14296dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
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:", "YOUR_HF_TOKEN", type="password")
26
-
27
- # Hugging Face login
28
- if HF_TOKEN and HF_TOKEN != "YOUR_HF_TOKEN":
29
- login(token=HF_TOKEN)
30
- else:
31
- st.sidebar.warning("Please enter a valid Hugging Face token to proceed.")
 
 
 
 
 
 
 
 
 
 
 
 
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: