Skip to content

Commit

Permalink
Implement alerts proof of concept in Gradio UI
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonDaniel committed Feb 6, 2024
1 parent 9d8cbf6 commit 0537995
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions neon_iris/web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(self, lang: str = None):
self.config = config.get('iris') or dict()
NeonAIClient.__init__(self, config.get("MQ"))
self._await_response = Event()
self._alerts = dict()
self._response = None
self._transcribed = None
self._current_tts = dict()
Expand Down Expand Up @@ -80,6 +81,14 @@ def _start_session(self):
self._profiles[sid]['user']['username'] = sid
return sid

def check_alerts(self, session_id: str):
if not self._alerts.get(session_id):
gradio.Info("No Alerts")
return session_id
while self._alerts.get(session_id):
gradio.Info(self._alerts[session_id].pop())
return session_id

def update_profile(self, stt_lang: str, tts_lang: str, tts_lang_2: str,
time: int, date: str, uom: str, city: str, state: str,
country: str, first: str, middle: str, last: str,
Expand Down Expand Up @@ -214,6 +223,9 @@ def run(self):
# inputs=[client_session],
# outputs=[tts_audio, client_session])
# Define settings UI
with gradio.Row():
submit = gradio.Button("Update User Settings")
check_alerts = gradio.Button("Check for Alerts")
with gradio.Row():
with gradio.Column():
lang = self.get_lang(client_session.value).split('-')[0]
Expand Down Expand Up @@ -253,14 +265,15 @@ def run(self):
pref_name = gradio.Textbox(label="Preferred Name")
email_addr = gradio.Textbox(label="Email Address")
# TODO: DoB, pic, about, phone?
submit = gradio.Button("Update User Settings")
submit.click(self.update_profile,
inputs=[stt_lang, tts_lang, tts_lang_2, time_format,
date_format, unit_of_measure, city, state,
country, first_name, middle_name, last_name,
pref_name, email_addr, client_session],
outputs=[client_session])
blocks.launch(server_name=address, server_port=port)
check_alerts.click(self.check_alerts, inputs=[client_session],
outputs=[client_session])
blocks.queue().launch(server_name=address, server_port=port)

def handle_klat_response(self, message: Message):
"""
Expand Down Expand Up @@ -307,6 +320,17 @@ def handle_api_response(self, message: Message):
if message.msg_type == "neon.audio_input.response":
self._transcribed = message.data.get("transcripts", [""])[0]

def handle_alert(self, message: Message):
"""
Handle an expired alert that was previously set by this session.
@param message: neon.alert_expired Message
"""
user = message.context['username']
LOG.info(f"Alert expired for user: {user}")
alert = f"Alert Expired: {message.data.get('alert_name')}"
self._alerts.setdefault(user, list())
self._alerts[user].append(alert)

def _handle_profile_update(self, message: Message):
updated_profile = message.data["profile"]
session_id = updated_profile['user']['username']
Expand Down

0 comments on commit 0537995

Please sign in to comment.