Update app.py
Browse files
app.py
CHANGED
|
@@ -53,9 +53,12 @@ model.to(DEVICE)
|
|
| 53 |
model.eval()
|
| 54 |
|
| 55 |
# ======================
|
| 56 |
-
# GENERATION
|
| 57 |
# ======================
|
| 58 |
def generate(user_input, history):
|
|
|
|
|
|
|
|
|
|
| 59 |
prompt = f"### Instrucci贸n:\n{user_input}\n\n### Respuesta:\n"
|
| 60 |
|
| 61 |
tokens = [tokenizer.bos_id()] + tokenizer.encode(prompt)
|
|
@@ -64,7 +67,7 @@ def generate(user_input, history):
|
|
| 64 |
with torch.no_grad():
|
| 65 |
output_ids = model.generate(
|
| 66 |
input_ids,
|
| 67 |
-
max_new_tokens=
|
| 68 |
temperature=0.8,
|
| 69 |
top_k=50,
|
| 70 |
top_p=0.9
|
|
@@ -86,11 +89,15 @@ def generate(user_input, history):
|
|
| 86 |
# ======================
|
| 87 |
# GRADIO UI
|
| 88 |
# ======================
|
| 89 |
-
with gr.Blocks(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
gr.Markdown("# 馃 MTP 1.1")
|
| 91 |
gr.Markdown("Modelo de lenguaje experimental")
|
| 92 |
|
| 93 |
-
chatbot = gr.Chatbot()
|
| 94 |
state = gr.State([])
|
| 95 |
|
| 96 |
textbox = gr.Textbox(
|
|
@@ -98,6 +105,17 @@ with gr.Blocks(css="footer{display:none}") as demo:
|
|
| 98 |
show_label=False
|
| 99 |
)
|
| 100 |
|
| 101 |
-
textbox.submit(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
model.eval()
|
| 54 |
|
| 55 |
# ======================
|
| 56 |
+
# GENERATION FUNCTION
|
| 57 |
# ======================
|
| 58 |
def generate(user_input, history):
|
| 59 |
+
if history is None:
|
| 60 |
+
history = []
|
| 61 |
+
|
| 62 |
prompt = f"### Instrucci贸n:\n{user_input}\n\n### Respuesta:\n"
|
| 63 |
|
| 64 |
tokens = [tokenizer.bos_id()] + tokenizer.encode(prompt)
|
|
|
|
| 67 |
with torch.no_grad():
|
| 68 |
output_ids = model.generate(
|
| 69 |
input_ids,
|
| 70 |
+
max_new_tokens=120,
|
| 71 |
temperature=0.8,
|
| 72 |
top_k=50,
|
| 73 |
top_p=0.9
|
|
|
|
| 89 |
# ======================
|
| 90 |
# GRADIO UI
|
| 91 |
# ======================
|
| 92 |
+
with gr.Blocks(
|
| 93 |
+
css="footer{display:none}",
|
| 94 |
+
title="MTP Chatbot"
|
| 95 |
+
) as demo:
|
| 96 |
+
|
| 97 |
gr.Markdown("# 馃 MTP 1.1")
|
| 98 |
gr.Markdown("Modelo de lenguaje experimental")
|
| 99 |
|
| 100 |
+
chatbot = gr.Chatbot(height=450)
|
| 101 |
state = gr.State([])
|
| 102 |
|
| 103 |
textbox = gr.Textbox(
|
|
|
|
| 105 |
show_label=False
|
| 106 |
)
|
| 107 |
|
| 108 |
+
textbox.submit(
|
| 109 |
+
fn=generate,
|
| 110 |
+
inputs=[textbox, state],
|
| 111 |
+
outputs=[chatbot, state]
|
| 112 |
+
)
|
| 113 |
|
| 114 |
+
# ======================
|
| 115 |
+
# LAUNCH
|
| 116 |
+
# ======================
|
| 117 |
+
demo.launch(
|
| 118 |
+
server_name="0.0.0.0",
|
| 119 |
+
server_port=7860,
|
| 120 |
+
show_api=True
|
| 121 |
+
)
|