Spaces:
Runtime error
Runtime error
Print out traceback to Output when something gets wrong.
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
#!/usr/bin/env python
|
2 |
# or gradio app.py
|
3 |
|
|
|
4 |
import gradio as gr
|
5 |
import chat_client
|
6 |
|
@@ -11,8 +12,13 @@ def generate(prompt, model, endseq, max_length,
|
|
11 |
do_sample, top_k, top_p, temperature,
|
12 |
add_stoptoken, copy_output):
|
13 |
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
if add_stoptoken:
|
18 |
prompt += "</s>" if "bloomz" in model else "\n\n"
|
@@ -44,20 +50,25 @@ def generate(prompt, model, endseq, max_length,
|
|
44 |
# don't wait to generator to return first result
|
45 |
yield [prompt2, output]
|
46 |
|
47 |
-
|
|
|
48 |
max_new_tokens=1,
|
49 |
do_sample=do_sample,
|
50 |
temperature=temperature,
|
51 |
top_k=top_k,
|
52 |
top_p=top_p,
|
53 |
extra_stop_sequences=seq
|
54 |
-
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
|
60 |
-
|
|
|
|
|
|
|
|
|
61 |
|
62 |
with gr.Blocks() as iface:
|
63 |
gr.Markdown("""# Petals playground
|
|
|
1 |
#!/usr/bin/env python
|
2 |
# or gradio app.py
|
3 |
|
4 |
+
import traceback
|
5 |
import gradio as gr
|
6 |
import chat_client
|
7 |
|
|
|
12 |
do_sample, top_k, top_p, temperature,
|
13 |
add_stoptoken, copy_output):
|
14 |
|
15 |
+
try:
|
16 |
+
client = chat_client.ModelClient(CHAT_URL)
|
17 |
+
client.open_session(f"bigscience/{model}-petals", max_length)
|
18 |
+
except Exception:
|
19 |
+
print(traceback.format_exc())
|
20 |
+
yield [prompt, "Error: " + traceback.format_exc()]
|
21 |
+
return
|
22 |
|
23 |
if add_stoptoken:
|
24 |
prompt += "</s>" if "bloomz" in model else "\n\n"
|
|
|
50 |
# don't wait to generator to return first result
|
51 |
yield [prompt2, output]
|
52 |
|
53 |
+
try:
|
54 |
+
for out in client.generate(prompt,
|
55 |
max_new_tokens=1,
|
56 |
do_sample=do_sample,
|
57 |
temperature=temperature,
|
58 |
top_k=top_k,
|
59 |
top_p=top_p,
|
60 |
extra_stop_sequences=seq
|
61 |
+
):
|
62 |
|
63 |
+
output += out
|
64 |
+
if copy_output:
|
65 |
+
prompt2 += out
|
66 |
|
67 |
+
yield [prompt2, output]
|
68 |
+
except Exception:
|
69 |
+
print(traceback.format_exc())
|
70 |
+
yield [prompt, "Error: " + traceback.format_exc()]
|
71 |
+
return
|
72 |
|
73 |
with gr.Blocks() as iface:
|
74 |
gr.Markdown("""# Petals playground
|