File size: 1,830 Bytes
2de9fb7
 
 
 
 
 
 
 
 
 
 
 
 
 
1b0b559
 
2de9fb7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1b0b559
2de9fb7
 
 
 
 
1b0b559
 
2de9fb7
 
 
 
1b0b559
 
 
 
 
 
2de9fb7
1b0b559
 
 
 
2de9fb7
1b0b559
2de9fb7
 
 
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
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()