Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,21 @@
|
|
| 1 |
from llama_cpp import Llama
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
llm = Llama(
|
| 6 |
-
model_path=
|
| 7 |
n_ctx=2048,
|
| 8 |
n_threads=2
|
| 9 |
)
|
| 10 |
|
| 11 |
-
#
|
| 12 |
SYSTEM_PROMPT = """Tu es un assistant IA utile, clair et concis.
|
| 13 |
Tu expliques simplement.
|
| 14 |
Tu évites les réponses trop longues.
|
|
@@ -28,16 +35,17 @@ def chat(user_input):
|
|
| 28 |
prompt,
|
| 29 |
max_tokens=200,
|
| 30 |
temperature=0.7,
|
| 31 |
-
stop=["<|user|>", "</s>"]
|
| 32 |
)
|
| 33 |
|
| 34 |
return output["choices"][0]["text"].strip()
|
| 35 |
|
|
|
|
| 36 |
iface = gr.Interface(
|
| 37 |
fn=chat,
|
| 38 |
inputs=gr.Textbox(lines=3, placeholder="Pose ta question..."),
|
| 39 |
outputs="text",
|
| 40 |
-
title="Phi-2 Chatbot
|
| 41 |
)
|
| 42 |
|
| 43 |
iface.launch()
|
|
|
|
| 1 |
from llama_cpp import Llama
|
| 2 |
+
from huggingface_hub import hf_hub_download
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
# 🔥 Télécharger le modèle au runtime (PAS stocké dans le repo)
|
| 6 |
+
model_path = hf_hub_download(
|
| 7 |
+
repo_id="TheBloke/phi-2-GGUF",
|
| 8 |
+
filename="phi-2.Q4_K_M.gguf"
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
# 🧠 Charger le modèle
|
| 12 |
llm = Llama(
|
| 13 |
+
model_path=model_path,
|
| 14 |
n_ctx=2048,
|
| 15 |
n_threads=2
|
| 16 |
)
|
| 17 |
|
| 18 |
+
# 🎭 Prompt système
|
| 19 |
SYSTEM_PROMPT = """Tu es un assistant IA utile, clair et concis.
|
| 20 |
Tu expliques simplement.
|
| 21 |
Tu évites les réponses trop longues.
|
|
|
|
| 35 |
prompt,
|
| 36 |
max_tokens=200,
|
| 37 |
temperature=0.7,
|
| 38 |
+
stop=["<|user|>", "<|system|>", "</s>"]
|
| 39 |
)
|
| 40 |
|
| 41 |
return output["choices"][0]["text"].strip()
|
| 42 |
|
| 43 |
+
# 🌐 Interface Gradio
|
| 44 |
iface = gr.Interface(
|
| 45 |
fn=chat,
|
| 46 |
inputs=gr.Textbox(lines=3, placeholder="Pose ta question..."),
|
| 47 |
outputs="text",
|
| 48 |
+
title="Phi-2 Chatbot (GGUF)"
|
| 49 |
)
|
| 50 |
|
| 51 |
iface.launch()
|