Skip to content

Commit

Permalink
Make streaming/generator case work for client
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudotensor committed Apr 11, 2023
1 parent 1b1fe40 commit ebaedb7
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions client_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import time
import os
os.environ['HF_HUB_DISABLE_TELEMETRY'] = '1'
from gradio_client import Client

client = Client("http://localhost:7860")
Expand All @@ -6,7 +9,7 @@
instruction = "Who are you?"
iinput = ''
context = ''
stream_output = False
stream_output = True
prompt_type = 'human_bot'
temperature = 0.1
top_p = 0.75
Expand Down Expand Up @@ -58,14 +61,26 @@ def test_client_basic():
with open(foofile, 'wt') as f:
json.dump([['', None]], f)
args += [foofile]
for res in client.predict(
*tuple(args),
api_name=api_name,
):
print(res)
res_file = client.predict(*tuple(args), api_name='/instruction_bot')
res = json.load(open(res_file, "rt"))[-1][-1]
print(md_to_text(res))
if not stream_output:
for res in client.predict(
*tuple(args),
api_name=api_name,
):
print(res)
res_file = client.predict(*tuple(args), api_name='/instruction_bot')
res = json.load(open(res_file, "rt"))[-1][-1]
print(md_to_text(res))
else:
print("streaming instruction_bot", flush=True)
job = client.submit(*tuple(args), api_name='/instruction_bot')
while not job.done():
outputs_list = job.communicator.job.outputs
if outputs_list:
res_file = job.communicator.job.outputs[-1]
res = json.load(open(res_file, "rt"))[-1][-1]
print(md_to_text(res))
time.sleep(0.1)
print(job.outputs())


import markdown # pip install markdown
Expand Down

0 comments on commit ebaedb7

Please sign in to comment.