Spaces:
Runtime error
Runtime error
Fix trans_api
Browse files
app.py
CHANGED
|
@@ -97,20 +97,28 @@ def predict(input, chatbot, max_length, top_p, temperature, history, past_key_va
|
|
| 97 |
|
| 98 |
|
| 99 |
def trans_api(input, max_length=4096, top_p=0.8, temperature=0.2):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
try:
|
| 101 |
-
res = model.
|
| 102 |
tokenizer,
|
| 103 |
input,
|
| 104 |
history=[],
|
| 105 |
past_key_values=None,
|
| 106 |
-
return_past_key_values=False,
|
| 107 |
max_length=max_length,
|
| 108 |
top_p=top_p,
|
| 109 |
temperature=temperature,
|
| 110 |
)
|
| 111 |
-
logger.debug(f"{res=}")
|
| 112 |
except Exception as exc:
|
| 113 |
logger.error(exc)
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
|
| 116 |
def reset_user_input():
|
|
@@ -167,8 +175,9 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 167 |
with gr.Accordion("For Translation API", open=False):
|
| 168 |
input_text = gr.Text()
|
| 169 |
tr_btn = gr.Button("Go", variant="primary")
|
| 170 |
-
|
| 171 |
-
|
|
|
|
| 172 |
# demo.queue().launch(share=False, inbrowser=True)
|
| 173 |
# demo.queue().launch(share=True, inbrowser=True, debug=True)
|
| 174 |
|
|
|
|
| 97 |
|
| 98 |
|
| 99 |
def trans_api(input, max_length=4096, top_p=0.8, temperature=0.2):
|
| 100 |
+
if max_length < 100:
|
| 101 |
+
max_length = 4096
|
| 102 |
+
if top_p < 0.1:
|
| 103 |
+
top_p = 0.8
|
| 104 |
+
if temperature <= 0:
|
| 105 |
+
temperature = 0.01
|
| 106 |
try:
|
| 107 |
+
res, _ = model.chat(
|
| 108 |
tokenizer,
|
| 109 |
input,
|
| 110 |
history=[],
|
| 111 |
past_key_values=None,
|
|
|
|
| 112 |
max_length=max_length,
|
| 113 |
top_p=top_p,
|
| 114 |
temperature=temperature,
|
| 115 |
)
|
| 116 |
+
# logger.debug(f"{res=} \n{_=}")
|
| 117 |
except Exception as exc:
|
| 118 |
logger.error(exc)
|
| 119 |
+
res = str(exc)
|
| 120 |
+
|
| 121 |
+
return res
|
| 122 |
|
| 123 |
|
| 124 |
def reset_user_input():
|
|
|
|
| 175 |
with gr.Accordion("For Translation API", open=False):
|
| 176 |
input_text = gr.Text()
|
| 177 |
tr_btn = gr.Button("Go", variant="primary")
|
| 178 |
+
out_text = gr.Text()
|
| 179 |
+
tr_btn.click(trans_api, [input_text, max_length, top_p, temperature], out_text, show_progress=True, api_name="tr")
|
| 180 |
+
|
| 181 |
# demo.queue().launch(share=False, inbrowser=True)
|
| 182 |
# demo.queue().launch(share=True, inbrowser=True, debug=True)
|
| 183 |
|