import gradio as gr from transformers import pipeline # Load tiny model pipe = pipeline( "text-generation", model="Qwen/Qwen2.5-0.5B-Instruct", device="cpu", torch_dtype="auto" ) def chat(message, history): if history is None: history = [] # Build messages for the model messages = [{"role": "system", "content": "You are a helpful, creative assistant good at coding, vibing, stories, and worldbuilding."}] for human, assistant in history: messages.append({"role": "user", "content": human}) messages.append({"role": "assistant", "content": assistant}) messages.append({"role": "user", "content": message}) try: text = pipe.tokenizer.apply_chat_template( messages, tokenize=False, add_generation_prompt=True ) response = pipe( text, max_new_tokens=1024, temperature=0.8, top_p=0.9, do_sample=True, return_full_text=False ) reply = response[0]['generated_text'].strip() except Exception as e: reply = f"Error: {str(e)}" # Use tuple format - most compatible with Gradio history.append((message, reply)) return history with gr.Blocks(title="Holodeck AI") as demo: gr.Markdown("# 🧠 Holodeck AI Chat\nTiny model for coding, vibing & worldbuilding") chatbot = gr.Chatbot(height=500) msg = gr.Textbox( placeholder="Type your message here...", label="Your Message", lines=3 ) send_btn = gr.Button("Send", variant="primary") msg.submit(chat, [msg, chatbot], chatbot) send_btn.click(chat, [msg, chatbot], chatbot) demo.launch()