Spaces:
No application file
No application file
first version with ots working
Browse files- api/event_handlers/gradio_handler.py +14 -0
- api/server_gradio.py +23 -4
api/event_handlers/gradio_handler.py
CHANGED
@@ -24,8 +24,22 @@ class GradioEventHandler(AsyncCallbackHandler):
|
|
24 |
}
|
25 |
)
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
async def on_chat_model_start(self, *args, **kwargs):
|
28 |
self.info_box('[CHAT START]')
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
async def on_llm_new_token(self, token: str, **kwargs):
|
31 |
if token:
|
|
|
24 |
}
|
25 |
)
|
26 |
|
27 |
+
def ots_box(self, message: str):
|
28 |
+
self.queue.put(
|
29 |
+
{
|
30 |
+
"type": "ots",
|
31 |
+
"message": message,
|
32 |
+
}
|
33 |
+
)
|
34 |
+
|
35 |
async def on_chat_model_start(self, *args, **kwargs):
|
36 |
self.info_box('[CHAT START]')
|
37 |
+
self.ots_box("""
|
38 |
+
<img
|
39 |
+
src="https://huggingface.co/spaces/ryanbalch/IFX-huge-league/resolve/main/assets/landing.png"
|
40 |
+
style="max-width: 100%; max-height: 100%; object-fit: contain; display: block; margin: 0 auto;"
|
41 |
+
/>
|
42 |
+
""")
|
43 |
|
44 |
async def on_llm_new_token(self, token: str, **kwargs):
|
45 |
if token:
|
api/server_gradio.py
CHANGED
@@ -18,6 +18,11 @@ MESSAGE_TYPE_MAP = {
|
|
18 |
"ai": AIMessage,
|
19 |
# Add other message types as needed
|
20 |
}
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
|
23 |
class AppState(BaseModel):
|
@@ -29,6 +34,12 @@ class AppState(BaseModel):
|
|
29 |
history: list = []
|
30 |
zep_session_id: str = ""
|
31 |
freeplay_session_id: str = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
def ensure_sessions(self):
|
34 |
if not self.zep_session_id:
|
@@ -102,6 +113,11 @@ def submit_helper(state, handler, user_query):
|
|
102 |
if token["type"] == "info":
|
103 |
gr.Info(token["message"])
|
104 |
continue
|
|
|
|
|
|
|
|
|
|
|
105 |
result += token
|
106 |
yield state, result
|
107 |
|
@@ -130,8 +146,11 @@ with gr.Blocks() as demo:
|
|
130 |
value=state.value.last_name)
|
131 |
|
132 |
with gr.Row():
|
133 |
-
llm_response = gr.Textbox(label="LLM Response", lines=
|
134 |
-
ots_box = gr.
|
|
|
|
|
|
|
135 |
|
136 |
with gr.Row(scale=1):
|
137 |
with gr.Column(scale=1):
|
@@ -180,9 +199,9 @@ with gr.Blocks() as demo:
|
|
180 |
|
181 |
### Events
|
182 |
|
183 |
-
@state.change(inputs=[state], outputs=[count_disp, persona_disp, zep_session_id_disp, freeplay_session_id_disp, user_query])
|
184 |
def state_change(state):
|
185 |
-
return state.count, state.persona, state.zep_session_id, state.freeplay_session_id, ""
|
186 |
|
187 |
@clear_state_btn.click(outputs=[state, llm_response, persona, user_query, email, first_name, last_name])
|
188 |
def clear_state():
|
|
|
18 |
"ai": AIMessage,
|
19 |
# Add other message types as needed
|
20 |
}
|
21 |
+
ots_default = """
|
22 |
+
<div style="display: flex; justify-content: center; align-items: center; width: 100%; max-width: 727px; height: 363px; margin: 0 auto;">
|
23 |
+
{content}
|
24 |
+
</div>
|
25 |
+
"""
|
26 |
|
27 |
|
28 |
class AppState(BaseModel):
|
|
|
34 |
history: list = []
|
35 |
zep_session_id: str = ""
|
36 |
freeplay_session_id: str = ""
|
37 |
+
ots_content: str = ots_default.format(content="""
|
38 |
+
<img
|
39 |
+
src="https://huggingface.co/spaces/ryanbalch/IFX-huge-league/resolve/main/assets/huge_landing.png"
|
40 |
+
style="max-width: 100%; max-height: 100%; object-fit: contain; display: block; margin: 0 auto;"
|
41 |
+
/>
|
42 |
+
""")
|
43 |
|
44 |
def ensure_sessions(self):
|
45 |
if not self.zep_session_id:
|
|
|
113 |
if token["type"] == "info":
|
114 |
gr.Info(token["message"])
|
115 |
continue
|
116 |
+
if token["type"] == "ots":
|
117 |
+
state.ots_content = ots_default.format(content=token["message"])
|
118 |
+
state = AppState(**state.model_dump())
|
119 |
+
yield state, result
|
120 |
+
continue
|
121 |
result += token
|
122 |
yield state, result
|
123 |
|
|
|
146 |
value=state.value.last_name)
|
147 |
|
148 |
with gr.Row():
|
149 |
+
llm_response = gr.Textbox(label="LLM Response", lines=15)
|
150 |
+
ots_box = gr.HTML(
|
151 |
+
label="OTS",
|
152 |
+
value=state.value.ots_content,
|
153 |
+
)
|
154 |
|
155 |
with gr.Row(scale=1):
|
156 |
with gr.Column(scale=1):
|
|
|
199 |
|
200 |
### Events
|
201 |
|
202 |
+
@state.change(inputs=[state], outputs=[count_disp, persona_disp, zep_session_id_disp, freeplay_session_id_disp, user_query, ots_box])
|
203 |
def state_change(state):
|
204 |
+
return state.count, state.persona, state.zep_session_id, state.freeplay_session_id, "", state.ots_content
|
205 |
|
206 |
@clear_state_btn.click(outputs=[state, llm_response, persona, user_query, email, first_name, last_name])
|
207 |
def clear_state():
|