Spaces:
Sleeping
Sleeping
Bypass login dialog if we already logged in by hf auth command
#5
by ferrywuai - opened
- README.md +42 -4
- src/streamlit_app.py +7 -2
README.md
CHANGED
|
@@ -12,9 +12,47 @@ short_description: Test docker sdk streamlit template
|
|
| 12 |
license: mit
|
| 13 |
---
|
| 14 |
|
| 15 |
-
# Welcome to
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
license: mit
|
| 13 |
---
|
| 14 |
|
| 15 |
+
# Welcome to Chatbot!
|
| 16 |
|
| 17 |
+
The following command installs required packages of the chatbot.
|
| 18 |
|
| 19 |
+
```
|
| 20 |
+
pip install -r requirements.txt
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
The following commands provides API token to the chatbot. Choose from one of them.
|
| 24 |
+
|
| 25 |
+
- Login Hugging Face Hub
|
| 26 |
+
|
| 27 |
+
```
|
| 28 |
+
hf auth login
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
- Set HF_TOKEN environment variable
|
| 32 |
+
|
| 33 |
+
```
|
| 34 |
+
export HF_TOKEN=<Your Hugging Face Token>
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
The following command runs the chatbot.
|
| 38 |
+
|
| 39 |
+
```
|
| 40 |
+
streamlit run src/streamlit_app.py
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
Use browser to access the chatbot after you see the following message.
|
| 44 |
+
|
| 45 |
+
```
|
| 46 |
+
You can now view your Streamlit app in your browser.
|
| 47 |
+
|
| 48 |
+
Local URL: http://localhost:8501
|
| 49 |
+
Network URL: http://172.28.148.72:8501
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
Use Crtl+C to stop the chatbot.
|
| 53 |
+
|
| 54 |
+
Logout Hugging Face Hub if you have logged in.
|
| 55 |
+
|
| 56 |
+
```
|
| 57 |
+
hf auth logout
|
| 58 |
+
```
|
src/streamlit_app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
|
| 3 |
import streamlit as st
|
| 4 |
-
from huggingface_hub import InferenceClient
|
| 5 |
|
| 6 |
chat_parameters = {
|
| 7 |
"system_prompt": "You are a friendly Chatbot.",
|
|
@@ -62,8 +62,13 @@ def get_reponse(client, user_input):
|
|
| 62 |
|
| 63 |
|
| 64 |
def login():
|
|
|
|
| 65 |
env_token = os.getenv("HF_TOKEN")
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
st.session_state.hf_token = env_token
|
| 68 |
switch_page()
|
| 69 |
else:
|
|
|
|
| 1 |
import os
|
| 2 |
|
| 3 |
import streamlit as st
|
| 4 |
+
from huggingface_hub import HfFolder, InferenceClient
|
| 5 |
|
| 6 |
chat_parameters = {
|
| 7 |
"system_prompt": "You are a friendly Chatbot.",
|
|
|
|
| 62 |
|
| 63 |
|
| 64 |
def login():
|
| 65 |
+
api_token = HfFolder.get_token()
|
| 66 |
env_token = os.getenv("HF_TOKEN")
|
| 67 |
+
|
| 68 |
+
if api_token:
|
| 69 |
+
st.session_state.hf_token = api_token
|
| 70 |
+
switch_page()
|
| 71 |
+
elif env_token:
|
| 72 |
st.session_state.hf_token = env_token
|
| 73 |
switch_page()
|
| 74 |
else:
|