misukisu commited on
Commit
171d80a
·
verified ·
1 Parent(s): 388a25f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -13
app.py CHANGED
@@ -1,26 +1,32 @@
1
  import gradio as gr
2
  import subprocess
3
  import sys
4
- import os
5
- from llama_cpp import Llama
6
 
7
- # Asenna oikea wheel heti alussa (tämä on glibc-yhteensopiva HF Spaces -versio)
8
- wheel_url = "https://github.com/abetlen/llama-cpp-python/releases/download/v0.3.15/llama_cpp_python-0.3.15-cp311-cp311-linux_x86_64.whl"
9
 
 
10
  try:
11
- from llama_cpp import Llama
12
- print("llama-cpp-python jo asennettu.")
13
- except ImportError:
14
- print("Asennetaan llama-cpp-python wheel...")
15
  subprocess.check_call([sys.executable, "-m", "pip", "install", "--no-cache-dir", wheel_url])
16
- print("Asennus valmis.")
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
- # Malli (lataa tämä Spaceen tiedostona!)
19
- model_path = "Qwen3-1.7B-Q4_K_M.gguf"
20
 
21
  llm = Llama(
22
  model_path=model_path,
23
- n_ctx=4096, # pienempi ettei kaadu muistiin
24
  n_threads=2,
25
  n_batch=256,
26
  n_gpu_layers=0,
@@ -54,7 +60,7 @@ def chat_with_bot(message, history):
54
  demo = gr.ChatInterface(
55
  fn=chat_with_bot,
56
  title="Professional AI Assistant",
57
- description="Ask me anything - normal stuff or sensitive topics. Full detailed answers, no refusals.",
58
  theme=gr.themes.Soft(),
59
  chatbot=gr.Chatbot(height=600),
60
  textbox=gr.Textbox(placeholder="Type your message here...", lines=3)
 
1
  import gradio as gr
2
  import subprocess
3
  import sys
 
 
4
 
5
+ # ASENNA WHEEL ENSIN - TÄRKEIN OSA
6
+ wheel_url = "https://huggingface.co/Luigi/llama-cpp-python-wheels-hf-spaces-free-cpu/resolve/main/llama_cpp_python-0.3.22-cp310-cp310-linux_x86_64.whl"
7
 
8
+ print("Asennetaan llama-cpp-python wheel...")
9
  try:
 
 
 
 
10
  subprocess.check_call([sys.executable, "-m", "pip", "install", "--no-cache-dir", wheel_url])
11
+ print("Wheel asennettu onnistuneesti.")
12
+ except Exception as e:
13
+ print(f"Wheel-asennus epäonnistui: {e}")
14
+ # Jos Luigi ei toimi, kokeile abetlenin wheeliä
15
+ try:
16
+ fallback = "https://github.com/abetlen/llama-cpp-python/releases/download/v0.3.15/llama_cpp_python-0.3.15-cp311-cp311-linux_x86_64.whl"
17
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "--no-cache-dir", fallback])
18
+ print("Fallback wheel asennettu.")
19
+ except:
20
+ print("Kaikki wheelit failasivat. Tappakaa itsenne jo.")
21
+
22
+ # Nyt import
23
+ from llama_cpp import Llama
24
 
25
+ model_path = "Qwen3-1.7B-Q4_K_M.gguf" # varmista että tää on ladattu Spaceen!
 
26
 
27
  llm = Llama(
28
  model_path=model_path,
29
+ n_ctx=4096,
30
  n_threads=2,
31
  n_batch=256,
32
  n_gpu_layers=0,
 
60
  demo = gr.ChatInterface(
61
  fn=chat_with_bot,
62
  title="Professional AI Assistant",
63
+ description="Ask me anything - normal or sensitive topics. Full detailed answers, no refusals.",
64
  theme=gr.themes.Soft(),
65
  chatbot=gr.Chatbot(height=600),
66
  textbox=gr.Textbox(placeholder="Type your message here...", lines=3)