gradio-space / app.py
prodnobody's picture
Create app.py
8212834 verified
Raw
History Blame Contribute Delete
862 Bytes
import gradio as gr
def model_chat(message, history):
messages = []
for user_msg, bot_msg in history:
messages.append({"role": "user", "content": user_msg})
messages.append({"role": "assistant", "content": bot_msg})
messages.append({"role": "user", "content": message})
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True)
return response
demo_chat = gr.ChatInterface(
model_chat,
title="LiquidAI/LFM2.5-2.6B Chat Demo",
description="Chat with the LiquidAI/LFM2.5-2.6B model."
)
demo_chat.launch(share=True)