Aarshay Jain
commited on
Commit
•
eb12e97
1
Parent(s):
1f31bc5
setup ui with authentication
Browse files- .gitignore +165 -0
- README.md +1 -0
- app.py +88 -0
- client.py +36 -0
- requirements.txt +4 -0
.gitignore
ADDED
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Byte-compiled / optimized / DLL files
|
2 |
+
__pycache__/
|
3 |
+
*.py[cod]
|
4 |
+
*$py.class
|
5 |
+
|
6 |
+
# C extensions
|
7 |
+
*.so
|
8 |
+
|
9 |
+
# Distribution / packaging
|
10 |
+
.Python
|
11 |
+
build/
|
12 |
+
develop-eggs/
|
13 |
+
dist/
|
14 |
+
downloads/
|
15 |
+
eggs/
|
16 |
+
.eggs/
|
17 |
+
lib/
|
18 |
+
lib64/
|
19 |
+
parts/
|
20 |
+
sdist/
|
21 |
+
var/
|
22 |
+
wheels/
|
23 |
+
share/python-wheels/
|
24 |
+
*.egg-info/
|
25 |
+
.installed.cfg
|
26 |
+
*.egg
|
27 |
+
MANIFEST
|
28 |
+
|
29 |
+
# PyInstaller
|
30 |
+
# Usually these files are written by a python script from a template
|
31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
32 |
+
*.manifest
|
33 |
+
*.spec
|
34 |
+
|
35 |
+
# Installer logs
|
36 |
+
pip-log.txt
|
37 |
+
pip-delete-this-directory.txt
|
38 |
+
|
39 |
+
# Unit test / coverage reports
|
40 |
+
htmlcov/
|
41 |
+
.tox/
|
42 |
+
.nox/
|
43 |
+
.coverage
|
44 |
+
.coverage.*
|
45 |
+
.cache
|
46 |
+
nosetests.xml
|
47 |
+
coverage.xml
|
48 |
+
*.cover
|
49 |
+
*.py,cover
|
50 |
+
.hypothesis/
|
51 |
+
.pytest_cache/
|
52 |
+
cover/
|
53 |
+
|
54 |
+
# Translations
|
55 |
+
*.mo
|
56 |
+
*.pot
|
57 |
+
|
58 |
+
# Django stuff:
|
59 |
+
*.log
|
60 |
+
local_settings.py
|
61 |
+
db.sqlite3
|
62 |
+
db.sqlite3-journal
|
63 |
+
|
64 |
+
# Flask stuff:
|
65 |
+
instance/
|
66 |
+
.webassets-cache
|
67 |
+
|
68 |
+
# Scrapy stuff:
|
69 |
+
.scrapy
|
70 |
+
|
71 |
+
# Sphinx documentation
|
72 |
+
docs/_build/
|
73 |
+
|
74 |
+
# PyBuilder
|
75 |
+
.pybuilder/
|
76 |
+
target/
|
77 |
+
|
78 |
+
# Jupyter Notebook
|
79 |
+
.ipynb_checkpoints
|
80 |
+
|
81 |
+
# IPython
|
82 |
+
profile_default/
|
83 |
+
ipython_config.py
|
84 |
+
|
85 |
+
# pyenv
|
86 |
+
# For a library or package, you might want to ignore these files since the code is
|
87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
88 |
+
# .python-version
|
89 |
+
|
90 |
+
# pipenv
|
91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
94 |
+
# install all needed dependencies.
|
95 |
+
#Pipfile.lock
|
96 |
+
|
97 |
+
# poetry
|
98 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
100 |
+
# commonly ignored for libraries.
|
101 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
102 |
+
#poetry.lock
|
103 |
+
|
104 |
+
# pdm
|
105 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
106 |
+
#pdm.lock
|
107 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
108 |
+
# in version control.
|
109 |
+
# https://pdm.fming.dev/#use-with-ide
|
110 |
+
.pdm.toml
|
111 |
+
|
112 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
113 |
+
__pypackages__/
|
114 |
+
|
115 |
+
# Celery stuff
|
116 |
+
celerybeat-schedule
|
117 |
+
celerybeat.pid
|
118 |
+
|
119 |
+
# SageMath parsed files
|
120 |
+
*.sage.py
|
121 |
+
|
122 |
+
# Environments
|
123 |
+
.env
|
124 |
+
.venv
|
125 |
+
env/
|
126 |
+
venv/
|
127 |
+
ENV/
|
128 |
+
env.bak/
|
129 |
+
venv.bak/
|
130 |
+
|
131 |
+
# Spyder project settings
|
132 |
+
.spyderproject
|
133 |
+
.spyproject
|
134 |
+
|
135 |
+
# Rope project settings
|
136 |
+
.ropeproject
|
137 |
+
|
138 |
+
# mkdocs documentation
|
139 |
+
/site
|
140 |
+
|
141 |
+
# mypy
|
142 |
+
.mypy_cache/
|
143 |
+
.dmypy.json
|
144 |
+
dmypy.json
|
145 |
+
|
146 |
+
# Pyre type checker
|
147 |
+
.pyre/
|
148 |
+
|
149 |
+
# pytype static type analyzer
|
150 |
+
.pytype/
|
151 |
+
|
152 |
+
# Cython debug symbols
|
153 |
+
cython_debug/
|
154 |
+
|
155 |
+
# PyCharm
|
156 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
157 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
158 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
159 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
160 |
+
.idea/
|
161 |
+
|
162 |
+
scripts
|
163 |
+
.env.test
|
164 |
+
poetry.lock
|
165 |
+
pyproject.toml
|
README.md
CHANGED
@@ -7,6 +7,7 @@ sdk: gradio
|
|
7 |
sdk_version: 3.41.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
7 |
sdk_version: 3.41.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
hf_oauth: true
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import os
|
3 |
+
import random
|
4 |
+
import time
|
5 |
+
|
6 |
+
import gradio as gr
|
7 |
+
from dotenv import load_dotenv
|
8 |
+
|
9 |
+
from client import AppClient
|
10 |
+
|
11 |
+
load_dotenv(verbose=True)
|
12 |
+
|
13 |
+
|
14 |
+
def get_session_id():
|
15 |
+
return " || ".join([os.environ["TERM_SESSION_ID"], os.environ["LaunchInstanceID"], os.environ["SECURITYSESSIONID"]])
|
16 |
+
|
17 |
+
|
18 |
+
def respond(message, chat_history):
|
19 |
+
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
20 |
+
chat_history.append((message, bot_message))
|
21 |
+
time.sleep(2)
|
22 |
+
return "", chat_history
|
23 |
+
|
24 |
+
|
25 |
+
def check_credentials(username, password):
|
26 |
+
print(f"session id: {get_session_id()}")
|
27 |
+
user_id_response = AppClient.authenticate_user(username, password)
|
28 |
+
if user_id_response is None:
|
29 |
+
return False
|
30 |
+
return True
|
31 |
+
|
32 |
+
|
33 |
+
with gr.Blocks() as demo:
|
34 |
+
|
35 |
+
visibility_handler = gr.Accordion(label="", visible=False)
|
36 |
+
no_access_msg = gr.Textbox(value="Unfortunately, you do not have access to the project. Please reach out to the admin to get access",
|
37 |
+
visible=False)
|
38 |
+
|
39 |
+
def validate_user(profile: gr.OAuthProfile | None):
|
40 |
+
access_granted = False
|
41 |
+
if profile is not None:
|
42 |
+
print(profile)
|
43 |
+
access_granted = profile["preferred_username"] in ("FakeGradioUser", "aarshay")
|
44 |
+
|
45 |
+
print(f"access granted: {access_granted}")
|
46 |
+
if access_granted:
|
47 |
+
return visibility_handler.update(visible=True), no_access_msg.update(visible=False)
|
48 |
+
else:
|
49 |
+
return visibility_handler.update(visible=False), no_access_msg.update(visible=True)
|
50 |
+
|
51 |
+
login_button = gr.LoginButton()
|
52 |
+
gr.LogoutButton()
|
53 |
+
|
54 |
+
start_button = gr.Button(value="Let's get started!!")
|
55 |
+
start_button.click(validate_user, None, [visibility_handler, no_access_msg])
|
56 |
+
|
57 |
+
with visibility_handler:
|
58 |
+
|
59 |
+
chatbot = gr.Chatbot()
|
60 |
+
# agent_state = gr.State(interview_agent)
|
61 |
+
#
|
62 |
+
msg = gr.Textbox(label="Candidate response")
|
63 |
+
# total_cost = gr.Number(label="Total Cost")
|
64 |
+
# # clear = gr.Button("Clear")
|
65 |
+
#
|
66 |
+
# def user(user_message, history):
|
67 |
+
# return "", history + [[user_message, None]]
|
68 |
+
# #
|
69 |
+
# def bot(agent: InterviewAgent, history):
|
70 |
+
# user_message = history[-1][0]
|
71 |
+
# bot_message = agent.chat(user_message)
|
72 |
+
# history[-1][1] = bot_message
|
73 |
+
# return agent, history
|
74 |
+
#
|
75 |
+
# def update_cost(agent):
|
76 |
+
# return agent.llm_cost()
|
77 |
+
#
|
78 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
79 |
+
# msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
80 |
+
# bot, [agent_state, chatbot], [agent_state, chatbot]
|
81 |
+
# ).then(
|
82 |
+
# update_cost, [agent_state], [total_cost]
|
83 |
+
# )
|
84 |
+
# clear.click(lambda: None, None, chatbot, queue=False)
|
85 |
+
|
86 |
+
|
87 |
+
# demo.queue()
|
88 |
+
demo.launch()
|
client.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from typing import Literal
|
3 |
+
|
4 |
+
import requests
|
5 |
+
from pydantic import BaseModel
|
6 |
+
|
7 |
+
|
8 |
+
class CheckUserRequest(BaseModel):
|
9 |
+
email: str
|
10 |
+
password: str
|
11 |
+
|
12 |
+
|
13 |
+
class CheckUserResponse(BaseModel):
|
14 |
+
user_id: str | None
|
15 |
+
|
16 |
+
|
17 |
+
class AppClient:
|
18 |
+
|
19 |
+
url_validate_user = os.environ["VALIDATE_USER_ENDPOINT"]
|
20 |
+
|
21 |
+
@classmethod
|
22 |
+
def _call_endpoint(cls, endpoint, data):
|
23 |
+
headers = {
|
24 |
+
"Content-Type": "application/json",
|
25 |
+
}
|
26 |
+
response = requests.post(url=endpoint, json=data.model_dump(mode="json"), headers=headers)
|
27 |
+
assert response.status_code == 200
|
28 |
+
|
29 |
+
return response.json()
|
30 |
+
|
31 |
+
@classmethod
|
32 |
+
def authenticate_user(cls, username, password) -> str:
|
33 |
+
return "user123"
|
34 |
+
request = CheckUserRequest(email=username, password=password)
|
35 |
+
response_json = cls._call_endpoint(cls.url_validate_user, request)
|
36 |
+
return CheckUserResponse.model_validate_json(response_json).user_id
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
python-dotenv==1.0.0
|
2 |
+
pydantic==2.2.0
|
3 |
+
authlib
|
4 |
+
itsdangerous
|