Update app.py
Browse files
app.py
CHANGED
|
@@ -2,20 +2,25 @@ import subprocess
|
|
| 2 |
import sys
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
def install(package):
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
# Asenna tarvittavat paketit
|
| 9 |
print("Asennetaan paketit...")
|
| 10 |
-
|
| 11 |
-
|
| 12 |
install("huggingface_hub")
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
from huggingface_hub import hf_hub_download
|
| 15 |
import gradio as gr
|
| 16 |
from llama_cpp import Llama
|
| 17 |
|
| 18 |
-
# Malli (Gemma 4 E4B - paras sun setupille)
|
| 19 |
MODEL_REPO = "unsloth/gemma-4-E4B-it-GGUF"
|
| 20 |
MODEL_FILE = "gemma-4-E4B-it-Q4_K_M.gguf"
|
| 21 |
MODEL_DIR = "./models"
|
|
@@ -24,7 +29,7 @@ os.makedirs(MODEL_DIR, exist_ok=True)
|
|
| 24 |
model_path = os.path.join(MODEL_DIR, MODEL_FILE)
|
| 25 |
|
| 26 |
if not os.path.exists(model_path):
|
| 27 |
-
print("Ladataan malli Hugging Facesta (ensimmäinen kerta voi kestää
|
| 28 |
hf_hub_download(
|
| 29 |
repo_id=MODEL_REPO,
|
| 30 |
filename=MODEL_FILE,
|
|
@@ -33,12 +38,12 @@ if not os.path.exists(model_path):
|
|
| 33 |
)
|
| 34 |
print("Malli ladattu!")
|
| 35 |
|
| 36 |
-
print("Ladataan malli...")
|
| 37 |
llm = Llama(
|
| 38 |
model_path=model_path,
|
| 39 |
-
n_ctx=4096,
|
| 40 |
-
n_threads=2,
|
| 41 |
-
n_gpu_layers=0,
|
| 42 |
verbose=False
|
| 43 |
)
|
| 44 |
|
|
@@ -54,5 +59,5 @@ print("Käynnistetään Gradio...")
|
|
| 54 |
gr.ChatInterface(
|
| 55 |
chat,
|
| 56 |
title="Gemma 4 E4B - Paikallinen chat",
|
| 57 |
-
description="Puhut suoraan mallin kanssa
|
| 58 |
).launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 2 |
import sys
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
def install(package, extra_args=None):
|
| 6 |
+
cmd = [sys.executable, "-m", "pip", "install", package]
|
| 7 |
+
if extra_args:
|
| 8 |
+
cmd.extend(extra_args)
|
| 9 |
+
subprocess.check_call(cmd)
|
| 10 |
|
|
|
|
| 11 |
print("Asennetaan paketit...")
|
| 12 |
+
|
| 13 |
+
# Gradio on jo asennettu
|
| 14 |
install("huggingface_hub")
|
| 15 |
|
| 16 |
+
# llama-cpp-python CPU-versiolla (tärkeä korjaus)
|
| 17 |
+
install("llama-cpp-python", ["--extra-index-url", "https://abetlen.github.io/llama-cpp-python/whl/cpu"])
|
| 18 |
+
|
| 19 |
from huggingface_hub import hf_hub_download
|
| 20 |
import gradio as gr
|
| 21 |
from llama_cpp import Llama
|
| 22 |
|
| 23 |
+
# Malli (Gemma 4 E4B - paras sun 2vCPU + 16GB setupille)
|
| 24 |
MODEL_REPO = "unsloth/gemma-4-E4B-it-GGUF"
|
| 25 |
MODEL_FILE = "gemma-4-E4B-it-Q4_K_M.gguf"
|
| 26 |
MODEL_DIR = "./models"
|
|
|
|
| 29 |
model_path = os.path.join(MODEL_DIR, MODEL_FILE)
|
| 30 |
|
| 31 |
if not os.path.exists(model_path):
|
| 32 |
+
print("Ladataan malli Hugging Facesta (ensimmäinen kerta voi kestää muutaman minuutin)...")
|
| 33 |
hf_hub_download(
|
| 34 |
repo_id=MODEL_REPO,
|
| 35 |
filename=MODEL_FILE,
|
|
|
|
| 38 |
)
|
| 39 |
print("Malli ladattu!")
|
| 40 |
|
| 41 |
+
print("Ladataan malli muistiin...")
|
| 42 |
llm = Llama(
|
| 43 |
model_path=model_path,
|
| 44 |
+
n_ctx=4096,
|
| 45 |
+
n_threads=2, # sun 2 vCPU
|
| 46 |
+
n_gpu_layers=0, # CPU only
|
| 47 |
verbose=False
|
| 48 |
)
|
| 49 |
|
|
|
|
| 59 |
gr.ChatInterface(
|
| 60 |
chat,
|
| 61 |
title="Gemma 4 E4B - Paikallinen chat",
|
| 62 |
+
description="Toimii sun laitteella. Puhut suoraan mallin kanssa selaimessa."
|
| 63 |
).launch(server_name="0.0.0.0", server_port=7860)
|