Update app.py
Browse files
app.py
CHANGED
@@ -18,17 +18,17 @@ generation_config = GenerationConfig(
|
|
18 |
pad_token_id=tokenizer.unk_token_id
|
19 |
)
|
20 |
def ask(text):
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
outputs = model.generate(**inputs, generation_config=generation_config,
|
31 |
return_dict_in_generate=True)
|
32 |
-
|
|
|
33 |
iface = gr.Interface(fn=ask, inputs="text", outputs="text")
|
34 |
iface.launch()
|
|
|
18 |
pad_token_id=tokenizer.unk_token_id
|
19 |
)
|
20 |
def ask(text):
|
21 |
+
messages = [
|
22 |
+
{
|
23 |
+
"role": "user",
|
24 |
+
"content": str(text),
|
25 |
+
},
|
26 |
+
]
|
27 |
+
inputs = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to("cuda")
|
28 |
+
inputs_length = inputs.shape[1]
|
29 |
+
outputs = model.generate(inputs, generation_config=generation_config,
|
|
|
30 |
return_dict_in_generate=True)
|
31 |
+
outputs = outputs.sequences[0, inputs_length:]
|
32 |
+
return tokenizer.decode(outputs, skip_special_tokens=True)
|
33 |
iface = gr.Interface(fn=ask, inputs="text", outputs="text")
|
34 |
iface.launch()
|