import os import gradio as gr from llama_cpp import Llama from huggingface_hub import hf_hub_download HF_REPO = "misukisu/kFlash-1.3" GGUF_FILE = "kFlash.gguf" print("Ladataan mallia HF:stä...") model_path = hf_hub_download(repo_id=HF_REPO, filename=GGUF_FILE) print(f"✓ Malli ladattu: {model_path}") SYSTEM_PROMPT = ( "Olet kFlash 1.3, Kreatixin tekemä tekoälymalli. Et ole Gemma etkä mikään " "Googlen malli. Kreatix löytyy TikTokista (@kreatix.dev) ja X:stä (@KreatixDev). " "Puhut rentona, puhekielisesti, saat kiroilla luontevasti." ) llm = Llama( model_path=model_path, n_ctx=2048, n_threads=2, verbose=False, ) def respond(message, history): messages = [{"role": "system", "content": SYSTEM_PROMPT}] for user_msg, bot_msg in history: messages.append({"role": "user", "content": user_msg}) if bot_msg: messages.append({"role": "assistant", "content": bot_msg}) messages.append({"role": "user", "content": message}) response = llm.create_chat_completion( messages=messages, max_tokens=512, temperature=0.8, top_p=0.9, ) return response["choices"][0]["message"]["content"] with gr.Blocks(title="kFlash 1.3") as demo: gr.Markdown("## 🤖 kFlash 1.3 — Kreatix") with gr.Row(): chatbot = gr.Chatbot(height=500) with gr.Row(): msg = gr.Textbox(label="Viesti", scale=4, placeholder="Kirjoita jotain...") clear = gr.Button("Tyhjennä", scale=1) def chat(message, chat_history): response = respond(message, chat_history) chat_history.append((message, response)) return "", chat_history msg.submit(chat, [msg, chatbot], [msg, chatbot]) clear.click(lambda: None, None, chatbot, queue=False) demo.queue().launch()