Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@ import gradio as gr
|
|
| 3 |
from llama_cpp import Llama
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
|
| 6 |
-
# Lataa GGUF HF:stä
|
| 7 |
HF_REPO = "misukisu/kFlash-1.3"
|
| 8 |
GGUF_FILE = "kFlash.gguf"
|
| 9 |
|
|
@@ -13,11 +12,8 @@ print(f"✓ Malli ladattu: {model_path}")
|
|
| 13 |
|
| 14 |
SYSTEM_PROMPT = (
|
| 15 |
"Olet kFlash 1.3, Kreatixin tekemä tekoälymalli. Et ole Gemma etkä mikään "
|
| 16 |
-
"Googlen malli
|
| 17 |
-
"
|
| 18 |
-
"(@kreatix.dev) ja X:stä (@KreatixDev). Puhut samaa kieltä kuin käyttäjä "
|
| 19 |
-
"(suomi tai englanti). Olet rento, puhekielinen, saat kiroilla luontevasti "
|
| 20 |
-
"kun tilanne sallii, mutta muuten olet ihan normaali ja fiksu keskustelija."
|
| 21 |
)
|
| 22 |
|
| 23 |
llm = Llama(
|
|
@@ -35,45 +31,31 @@ def respond(message, history):
|
|
| 35 |
messages.append({"role": "assistant", "content": bot_msg})
|
| 36 |
messages.append({"role": "user", "content": message})
|
| 37 |
|
| 38 |
-
|
| 39 |
messages=messages,
|
| 40 |
max_tokens=512,
|
| 41 |
temperature=0.8,
|
| 42 |
top_p=0.9,
|
| 43 |
-
stream=True,
|
| 44 |
)
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
for chunk in stream:
|
| 48 |
-
delta = chunk["choices"][0]["delta"].get("content", "")
|
| 49 |
-
partial += delta
|
| 50 |
-
yield partial
|
| 51 |
|
| 52 |
with gr.Blocks(title="kFlash 1.3") as demo:
|
| 53 |
gr.Markdown("## 🤖 kFlash 1.3 — Kreatix")
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
|
| 62 |
-
def
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
# Kerää vastaus kokonaan ennen kuin päivität UI:ta
|
| 67 |
-
full_response = ""
|
| 68 |
-
for partial in respond(history[-1][0], history[:-1]):
|
| 69 |
-
full_response = partial
|
| 70 |
-
|
| 71 |
-
history[-1][1] = full_response
|
| 72 |
-
return history
|
| 73 |
|
| 74 |
-
msg.submit(
|
| 75 |
-
bot_reply, chatbot, chatbot
|
| 76 |
-
)
|
| 77 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 78 |
|
| 79 |
demo.queue().launch()
|
|
|
|
| 3 |
from llama_cpp import Llama
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
|
|
|
|
| 6 |
HF_REPO = "misukisu/kFlash-1.3"
|
| 7 |
GGUF_FILE = "kFlash.gguf"
|
| 8 |
|
|
|
|
| 12 |
|
| 13 |
SYSTEM_PROMPT = (
|
| 14 |
"Olet kFlash 1.3, Kreatixin tekemä tekoälymalli. Et ole Gemma etkä mikään "
|
| 15 |
+
"Googlen malli. Kreatix löytyy TikTokista (@kreatix.dev) ja X:stä (@KreatixDev). "
|
| 16 |
+
"Puhut rentona, puhekielisesti, saat kiroilla luontevasti."
|
|
|
|
|
|
|
|
|
|
| 17 |
)
|
| 18 |
|
| 19 |
llm = Llama(
|
|
|
|
| 31 |
messages.append({"role": "assistant", "content": bot_msg})
|
| 32 |
messages.append({"role": "user", "content": message})
|
| 33 |
|
| 34 |
+
response = llm.create_chat_completion(
|
| 35 |
messages=messages,
|
| 36 |
max_tokens=512,
|
| 37 |
temperature=0.8,
|
| 38 |
top_p=0.9,
|
|
|
|
| 39 |
)
|
| 40 |
+
|
| 41 |
+
return response["choices"][0]["message"]["content"]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
with gr.Blocks(title="kFlash 1.3") as demo:
|
| 44 |
gr.Markdown("## 🤖 kFlash 1.3 — Kreatix")
|
| 45 |
|
| 46 |
+
with gr.Row():
|
| 47 |
+
chatbot = gr.Chatbot(height=500)
|
| 48 |
+
|
| 49 |
+
with gr.Row():
|
| 50 |
+
msg = gr.Textbox(label="Viesti", scale=4, placeholder="Kirjoita jotain...")
|
| 51 |
+
clear = gr.Button("Tyhjennä", scale=1)
|
| 52 |
|
| 53 |
+
def chat(message, chat_history):
|
| 54 |
+
response = respond(message, chat_history)
|
| 55 |
+
chat_history.append((message, response))
|
| 56 |
+
return "", chat_history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
msg.submit(chat, [msg, chatbot], [msg, chatbot])
|
|
|
|
|
|
|
| 59 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 60 |
|
| 61 |
demo.queue().launch()
|