devalender commited on
Commit
e954df4
·
1 Parent(s): fe39ef9

Switch from llama-cpp to ctransformers (no compilation)

Browse files
Files changed (2) hide show
  1. app.py +17 -14
  2. requirements.txt +1 -2
app.py CHANGED
@@ -1,29 +1,32 @@
1
  import gradio as gr
2
  from huggingface_hub import hf_hub_download
3
- import llama_cpp
4
- import os
5
 
6
- MODEL_REPO = "bartowski/Mistral-7B-Instruct-v0.3-GGUF"
7
- MODEL_FILE = "Mistral-7B-Instruct-v0.3-Q4_K_M.gguf"
8
 
9
  print("📥 Téléchargement du modèle...")
10
  model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE, resume=True)
11
 
12
  print("⚙️ Chargement du modèle...")
13
- llm = llama_cpp.Llama(
14
- model_path=model_path,
15
- n_ctx=2048,
16
- n_threads=2,
17
- n_batch=256,
18
- n_gpu_layers=0,
19
- verbose=False
20
  )
21
  print("✅ Modèle chargé !")
22
 
23
  def respond(message, history):
24
  prompt = f"<s>[INST] {message} [/INST]"
25
- response = llm(prompt, max_tokens=256, temperature=0.7, top_p=0.95, stop=["</s>", "[INST]", "[/INST]"], echo=False)
26
- return response["choices"][0]["text"].strip()
 
 
 
 
 
 
27
 
28
- demo = gr.ChatInterface(fn=respond, title="🤖 Assistant Mistral 7B (GGUF optimisé)")
29
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
1
  import gradio as gr
2
  from huggingface_hub import hf_hub_download
3
+ from ctransformers import AutoModelForCausalLM
 
4
 
5
+ MODEL_REPO = "TheBloke/Mistral-7B-Instruct-v0.3-GGUF"
6
+ MODEL_FILE = "mistral-7b-instruct-v0.3.Q4_K_M.gguf"
7
 
8
  print("📥 Téléchargement du modèle...")
9
  model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE, resume=True)
10
 
11
  print("⚙️ Chargement du modèle...")
12
+ llm = AutoModelForCausalLM.from_pretrained(
13
+ model_path,
14
+ model_type="mistral",
15
+ threads=2,
16
+ context_length=2048,
17
+ max_new_tokens=256
 
18
  )
19
  print("✅ Modèle chargé !")
20
 
21
  def respond(message, history):
22
  prompt = f"<s>[INST] {message} [/INST]"
23
+ response = llm.generate(prompt, temperature=0.7)
24
+ return response.strip()
25
+
26
+ demo = gr.ChatInterface(
27
+ fn=respond,
28
+ title="🤖 Assistant Mistral 7B",
29
+ description="Version GGUF optimisée - réponses ~30-60 secondes"
30
+ )
31
 
 
32
  demo.launch(server_name="0.0.0.0", server_port=7860)
requirements.txt CHANGED
@@ -1,4 +1,3 @@
1
  gradio
2
- --find-links https://github.com/abetlen/llama-cpp-python/releases/tag/v0.2.90
3
- llama-cpp-python
4
  huggingface-hub
 
1
  gradio
2
+ ctransformers
 
3
  huggingface-hub