Spaces:
Sleeping
Sleeping
File size: 1,769 Bytes
3126317 b1e9041 3126317 3ecbad4 b1e9041 3126317 b1e9041 23fea08 f343b1d 3ecbad4 526db1a 63032c2 b854063 63032c2 3126317 63032c2 b1e9041 63032c2 b1e9041 5899284 b1e9041 63032c2 b1e9041 3126317 63032c2 b1e9041 63032c2 3126317 23fea08 3126317 3ecbad4 b854063 3126317 f343b1d b854063 526db1a b1e9041 23fea08 b1e9041 5899284 b1e9041 3126317 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | 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() |