Commit ·
4ac290a
1
Parent(s): dc4c54a
Update for Browser Storage
Browse files
app.py
CHANGED
|
@@ -142,16 +142,31 @@ def generate_session_id():
|
|
| 142 |
return str(uuid4())
|
| 143 |
|
| 144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
with gr.Blocks() as demo:
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
with gr.Accordion(
|
| 154 |
'Sign Up',
|
|
|
|
| 155 |
) as signup:
|
| 156 |
|
| 157 |
with gr.Column():
|
|
@@ -168,7 +183,7 @@ with gr.Blocks() as demo:
|
|
| 168 |
call_travel_ai,
|
| 169 |
type='messages',
|
| 170 |
title="AI Travel Partner",
|
| 171 |
-
additional_inputs=[
|
| 172 |
autofocus=True,
|
| 173 |
fill_height=True,
|
| 174 |
)
|
|
@@ -177,20 +192,31 @@ with gr.Blocks() as demo:
|
|
| 177 |
_name: str,
|
| 178 |
_email: str,
|
| 179 |
_phone: str,
|
| 180 |
-
|
| 181 |
):
|
| 182 |
"""Update the visibility of the sign up and chat interfaces."""
|
|
|
|
|
|
|
|
|
|
| 183 |
_status = submit_signup(_email, _name, _phone)
|
| 184 |
gr.Info(_status, duration=5, title='Sign Up Status')
|
|
|
|
|
|
|
| 185 |
|
| 186 |
return (
|
| 187 |
-
gr.update(visible=
|
| 188 |
-
gr.update(visible=
|
|
|
|
| 189 |
)
|
| 190 |
|
| 191 |
submit_button.click( # pylint: disable=no-member
|
| 192 |
update_visibility,
|
| 193 |
-
[name, email, phone],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
outputs=[signup, chat],
|
| 195 |
)
|
| 196 |
|
|
|
|
| 142 |
return str(uuid4())
|
| 143 |
|
| 144 |
|
| 145 |
+
# def render(session_id: str):
|
| 146 |
+
# """Render the session ID."""
|
| 147 |
+
# return session_id
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def on_load(local_storage):
|
| 151 |
+
"""Update the visibility of the sign up and chat interfaces."""
|
| 152 |
+
signed_up = local_storage[1]
|
| 153 |
+
return gr.update(visible=not signed_up), gr.update(visible=signed_up)
|
| 154 |
+
|
| 155 |
+
|
| 156 |
with gr.Blocks() as demo:
|
| 157 |
+
|
| 158 |
+
session = gr.BrowserState(["", False])
|
| 159 |
+
# gr.Textbox(
|
| 160 |
+
# value=render,
|
| 161 |
+
# visible=False,
|
| 162 |
+
# interactive=False,
|
| 163 |
+
# label="Session ID",
|
| 164 |
+
# inputs=[session],
|
| 165 |
+
# )
|
| 166 |
|
| 167 |
with gr.Accordion(
|
| 168 |
'Sign Up',
|
| 169 |
+
visible=lambda session: not session[1],
|
| 170 |
) as signup:
|
| 171 |
|
| 172 |
with gr.Column():
|
|
|
|
| 183 |
call_travel_ai,
|
| 184 |
type='messages',
|
| 185 |
title="AI Travel Partner",
|
| 186 |
+
additional_inputs=[session],
|
| 187 |
autofocus=True,
|
| 188 |
fill_height=True,
|
| 189 |
)
|
|
|
|
| 192 |
_name: str,
|
| 193 |
_email: str,
|
| 194 |
_phone: str,
|
| 195 |
+
local_storage: str
|
| 196 |
):
|
| 197 |
"""Update the visibility of the sign up and chat interfaces."""
|
| 198 |
+
print(local_storage)
|
| 199 |
+
# session_id, signed_up = local_storage
|
| 200 |
+
local_storage[0] = local_storage[0] or generate_session_id()
|
| 201 |
_status = submit_signup(_email, _name, _phone)
|
| 202 |
gr.Info(_status, duration=5, title='Sign Up Status')
|
| 203 |
+
if _status == 'Success':
|
| 204 |
+
local_storage[1] = True
|
| 205 |
|
| 206 |
return (
|
| 207 |
+
gr.update(visible=not local_storage[1]),
|
| 208 |
+
gr.update(visible=local_storage[1]),
|
| 209 |
+
local_storage
|
| 210 |
)
|
| 211 |
|
| 212 |
submit_button.click( # pylint: disable=no-member
|
| 213 |
update_visibility,
|
| 214 |
+
[name, email, phone, session],
|
| 215 |
+
outputs=[signup, chat, session],
|
| 216 |
+
)
|
| 217 |
+
demo.load( # pylint: disable=no-member
|
| 218 |
+
on_load,
|
| 219 |
+
[session],
|
| 220 |
outputs=[signup, chat],
|
| 221 |
)
|
| 222 |
|