Spaces:
Sleeping
Sleeping
Commit ·
e954df4
1
Parent(s): fe39ef9
Switch from llama-cpp to ctransformers (no compilation)
Browse files- app.py +17 -14
- 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
|
| 4 |
-
import os
|
| 5 |
|
| 6 |
-
MODEL_REPO = "
|
| 7 |
-
MODEL_FILE = "
|
| 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 =
|
| 14 |
-
model_path
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 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,
|
| 26 |
-
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 3 |
-
llama-cpp-python
|
| 4 |
huggingface-hub
|
|
|
|
| 1 |
gradio
|
| 2 |
+
ctransformers
|
|
|
|
| 3 |
huggingface-hub
|