Spaces:
No application file
No application file
first readme; cleaning up gradio code
Browse files- api/README.md +18 -0
- api/server_gradio.py +12 -125
api/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
# deploy
|
3 |
+
|
4 |
+
we need to do this in order:
|
5 |
+
|
6 |
+
```bash
|
7 |
+
# build the final image
|
8 |
+
make build-prod
|
9 |
+
# huggingface needs to either build the image itself, or we need to pull it from somewhere
|
10 |
+
# atm that's github container registry
|
11 |
+
# so we push it there
|
12 |
+
make push-prod-ghcr
|
13 |
+
# now we need to trigger a build in that repo
|
14 |
+
cd IFX-huge-league && make trigger-build
|
15 |
+
```
|
16 |
+
|
17 |
+
then wait for it to finish building
|
18 |
+
https://huggingface.co/spaces/ryanbalch/IFX-huge-league?logs=container
|
api/server_gradio.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import asyncio
|
2 |
import gradio as gr
|
3 |
-
import time
|
4 |
import os
|
5 |
from pydantic import BaseModel
|
6 |
from threading import Thread
|
@@ -12,6 +11,7 @@ from utils.zep_helpers import ZepClient
|
|
12 |
|
13 |
lorem_ipsum = """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."""
|
14 |
show_state = True
|
|
|
15 |
dev_mode = os.getenv("DEV_MODE", "").lower() == "true"
|
16 |
|
17 |
|
@@ -44,11 +44,13 @@ def submit_helper(state, handler, user_query):
|
|
44 |
state = AppState(**state.dict())
|
45 |
yield state, ""
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
52 |
|
53 |
def start_async_loop():
|
54 |
workflow_bundle, workflow_state = build_workflow_with_state(
|
@@ -165,136 +167,21 @@ with gr.Blocks() as demo:
|
|
165 |
new_state = AppState()
|
166 |
return new_state, "", new_state.persona, "", new_state.email, new_state.first_name, new_state.last_name
|
167 |
|
168 |
-
# @submit_btn.click(inputs=[state, user_query], outputs=[state, llm_response])
|
169 |
-
# def submit(state, user_query):
|
170 |
-
# state.count += 1
|
171 |
-
# state.ensure_sessions()
|
172 |
-
# state = AppState(**state.dict())
|
173 |
-
|
174 |
-
# user_query = user_query or "tell me about some players in everglade fc"
|
175 |
-
# message = HumanMessage(content=user_query)
|
176 |
-
# state.history.append(message)
|
177 |
-
|
178 |
-
# result = ""
|
179 |
-
# yield state, result
|
180 |
-
# for i in range(0, len(lorem_ipsum), 4):
|
181 |
-
# time.sleep(0.1)
|
182 |
-
# result += lorem_ipsum[i:i+4]
|
183 |
-
# yield state, result
|
184 |
-
|
185 |
-
|
186 |
@submit_btn.click(inputs=[state, user_query], outputs=[state, llm_response])
|
187 |
def submit(state, user_query):
|
188 |
user_query = user_query or "tell me about some players in everglade fc"
|
189 |
yield from submit_helper(state, handler, user_query)
|
190 |
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
# state.user_query = user_query or "tell me about some players in everglade fc"
|
196 |
-
# message = HumanMessage(content=state.user_query)
|
197 |
-
# state.history.append(message)
|
198 |
-
# # workflow_state["messages"] = state.history
|
199 |
-
|
200 |
-
# def start_async_loop():
|
201 |
-
# workflow, workflow_state = build_workflow_with_state(
|
202 |
-
# handler=handler,
|
203 |
-
# zep_session_id=state.zep_session_id,
|
204 |
-
# freeplay_session_id=state.freeplay_session_id,
|
205 |
-
# email=state.email,
|
206 |
-
# first_name=state.first_name,
|
207 |
-
# last_name=state.last_name,
|
208 |
-
# persona=state.persona,
|
209 |
-
# messages=state.history,
|
210 |
-
# )
|
211 |
-
|
212 |
-
# async def run_workflow():
|
213 |
-
# await workflow.ainvoke(workflow_state)
|
214 |
-
|
215 |
-
# asyncio.run(run_workflow())
|
216 |
-
|
217 |
-
# thread = Thread(target=start_async_loop, daemon=True)
|
218 |
-
# thread.start()
|
219 |
-
|
220 |
-
# result = ""
|
221 |
-
# while True:
|
222 |
-
# token = handler.queue.get()
|
223 |
-
# # from colorama import Fore, Style
|
224 |
-
# # print(f'{Fore.GREEN}{token}{Style.RESET_ALL}')
|
225 |
-
# if token is None:
|
226 |
-
# break
|
227 |
-
# if isinstance(token, dict):
|
228 |
-
# if token["type"] == "info":
|
229 |
-
# gr.Info(token["message"])
|
230 |
-
# continue
|
231 |
-
# result += token
|
232 |
-
# yield result, state.zep_session_id, state.freeplay_session_id
|
233 |
-
|
234 |
-
# state.history.append(AIMessage(content=result))
|
235 |
-
|
236 |
-
# @user_query.submit(inputs=[user_query, state], outputs=[llm_response, state])
|
237 |
-
# def user_query_change(user_query, state):
|
238 |
-
# state.user_query = user_query
|
239 |
-
# state.zep_session_id = f"zep_{int(time.time())}"
|
240 |
-
# state.freeplay_session_id = f"freeplay_{int(time.time())}"
|
241 |
-
|
242 |
-
# result = state.user_query
|
243 |
-
# for i in range(0, len(lorem_ipsum), 4):
|
244 |
-
# time.sleep(0.1)
|
245 |
-
# result += lorem_ipsum[i:i+4]
|
246 |
-
# yield result, state
|
247 |
|
248 |
@persona.change(inputs=[persona, state], outputs=[persona_disp])
|
249 |
def persona_change(persona, state):
|
250 |
state.persona = persona
|
251 |
return persona
|
252 |
|
253 |
-
# @submit_btn.click(inputs=[state], outputs=[state, llm_response])
|
254 |
-
# def submit(state):
|
255 |
-
# state.count += 1
|
256 |
-
# new_state = AppState(**state.dict())
|
257 |
-
# result = 'hello'
|
258 |
-
# for i in range(0, len(lorem_ipsum), 4):
|
259 |
-
# time.sleep(0.1)
|
260 |
-
# result += lorem_ipsum[i:i+4]
|
261 |
-
# yield new_state, result
|
262 |
-
|
263 |
-
# @user_query.submit(inputs=[state], outputs=[count_disp, user_query])
|
264 |
-
# def user_query_change(state):
|
265 |
-
# state.count += 1
|
266 |
-
# return state.count, ''
|
267 |
-
|
268 |
-
# @clear_state_btn.click(inputs=[state], outputs=[count_disp, persona_disp, user_query, llm_response, zep_session_id_disp, freeplay_session_id_disp])
|
269 |
-
# def clear_state(state):
|
270 |
-
# state.clear()
|
271 |
-
# return state.count, state.persona, state.user_query, "", state.zep_session_id, state.freeplay_session_id
|
272 |
-
|
273 |
-
# @email.change(inputs=[email, state])
|
274 |
-
# def email_change(email, state):
|
275 |
-
# state.email = email
|
276 |
-
|
277 |
-
# @first_name.change(inputs=[first_name, state])
|
278 |
-
# def first_name_change(first_name, state):
|
279 |
-
# state.first_name = first_name
|
280 |
-
|
281 |
-
# @last_name.change(inputs=[last_name, state])
|
282 |
-
# def last_name_change(last_name, state):
|
283 |
-
# state.last_name = last_name
|
284 |
-
|
285 |
-
# @state.change(inputs=[state], outputs=[gr.ParamViewer()])
|
286 |
-
# def state_change(state):
|
287 |
-
# # return state.zep_session_id, state.freeplay_session_id
|
288 |
-
# docs = {
|
289 |
-
# "zep_session_id_ZZZZ": {
|
290 |
-
# "default": "None\n",
|
291 |
-
# "type": "str | None\n",
|
292 |
-
# "description": "Zep session ID.",
|
293 |
-
# },
|
294 |
-
# }
|
295 |
-
|
296 |
-
# return gr.ParamViewer(docs)
|
297 |
-
|
298 |
|
299 |
if __name__ == "__main__":
|
300 |
if dev_mode:
|
|
|
1 |
import asyncio
|
2 |
import gradio as gr
|
|
|
3 |
import os
|
4 |
from pydantic import BaseModel
|
5 |
from threading import Thread
|
|
|
11 |
|
12 |
lorem_ipsum = """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."""
|
13 |
show_state = True
|
14 |
+
fake_response = False
|
15 |
dev_mode = os.getenv("DEV_MODE", "").lower() == "true"
|
16 |
|
17 |
|
|
|
44 |
state = AppState(**state.dict())
|
45 |
yield state, ""
|
46 |
|
47 |
+
if fake_response:
|
48 |
+
result = lorem_ipsum
|
49 |
+
for i in range(0, len(lorem_ipsum), 4):
|
50 |
+
time.sleep(0.1)
|
51 |
+
result += lorem_ipsum[i:i+4]
|
52 |
+
yield state, result
|
53 |
+
return
|
54 |
|
55 |
def start_async_loop():
|
56 |
workflow_bundle, workflow_state = build_workflow_with_state(
|
|
|
167 |
new_state = AppState()
|
168 |
return new_state, "", new_state.persona, "", new_state.email, new_state.first_name, new_state.last_name
|
169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
@submit_btn.click(inputs=[state, user_query], outputs=[state, llm_response])
|
171 |
def submit(state, user_query):
|
172 |
user_query = user_query or "tell me about some players in everglade fc"
|
173 |
yield from submit_helper(state, handler, user_query)
|
174 |
|
175 |
+
@user_query.submit(inputs=[state, user_query], outputs=[state, llm_response])
|
176 |
+
def user_query_change(state, user_query):
|
177 |
+
user_query = user_query or "tell me about some players in everglade fc"
|
178 |
+
yield from submit_helper(state, handler, user_query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
|
180 |
@persona.change(inputs=[persona, state], outputs=[persona_disp])
|
181 |
def persona_change(persona, state):
|
182 |
state.persona = persona
|
183 |
return persona
|
184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
|
186 |
if __name__ == "__main__":
|
187 |
if dev_mode:
|