Spaces:
Runtime error
Runtime error
Commit
·
a723583
1
Parent(s):
2e6ed3a
handling authentication
Browse files- .gitignore +1 -0
- README.md +4 -0
- __pycache__/app.cpython-310.pyc +0 -0
- app.py +17 -0
- requirements.txt +2 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.env
|
README.md
CHANGED
|
@@ -7,6 +7,10 @@ sdk: docker
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 11 |
|
| 12 |
Create a Dockerfile as follows:
|
|
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
+
to run locally: chainlit run app.py -w
|
| 11 |
+
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 15 |
|
| 16 |
Create a Dockerfile as follows:
|
__pycache__/app.cpython-310.pyc
ADDED
|
Binary file (1.11 kB). View file
|
|
|
app.py
CHANGED
|
@@ -1,5 +1,22 @@
|
|
| 1 |
import chainlit as cl
|
|
|
|
|
|
|
|
|
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
@cl.on_message
|
| 5 |
async def main(message: cl.Message):
|
|
|
|
| 1 |
import chainlit as cl
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
from typing import Optional
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
+
@cl.on_chat_start
|
| 7 |
+
async def on_chat_start():
|
| 8 |
+
load_dotenv()
|
| 9 |
+
app_user = cl.user_session.get("user")
|
| 10 |
+
await cl.Message(f"Hello {app_user.username}").send()
|
| 11 |
+
|
| 12 |
+
@cl.password_auth_callback
|
| 13 |
+
def auth_callback(username: str, password: str) -> Optional[cl.AppUser]:
|
| 14 |
+
_username=os.environ.get('MY_USERNAME')
|
| 15 |
+
_password=os.environ.get('MY_PASSWORD')
|
| 16 |
+
if (username.upper(), password) == (_username, _password):
|
| 17 |
+
return cl.AppUser(username=_username, role="USER", provider="credentials")
|
| 18 |
+
else:
|
| 19 |
+
return None
|
| 20 |
|
| 21 |
@cl.on_message
|
| 22 |
async def main(message: cl.Message):
|
requirements.txt
CHANGED
|
@@ -1,2 +1,4 @@
|
|
| 1 |
chainlit
|
|
|
|
|
|
|
| 2 |
uvicorn
|
|
|
|
| 1 |
chainlit
|
| 2 |
+
load_dotenv
|
| 3 |
+
Optional
|
| 4 |
uvicorn
|