seckdaara commited on
Commit
fe60596
·
verified ·
1 Parent(s): bd9b66b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -1,8 +1,15 @@
1
  import gradio as gr
 
2
  from llama_cpp import Llama
3
 
4
- model_path = "gemma-2b-it-Q4_K_M.gguf"
 
 
 
 
 
5
 
 
6
  llm = Llama(model_path=model_path, n_ctx=2048, n_threads=2)
7
 
8
  def chatbot(message, history):
@@ -15,11 +22,11 @@ def chatbot(message, history):
15
  "Ne fais pas de diagnostic médical et précise toujours que l'utilisateur doit consulter "
16
  "un médecin pour tout problème grave. Réponds avec bienveillance et clarté.\n\n"
17
  )
18
-
19
  for human, bot in history:
20
  prompt += f"Utilisateur: {human}\nAssistant: {bot}\n"
21
  prompt += f"Utilisateur: {message}\nAssistant:"
22
-
23
  output = llm(prompt, max_tokens=300)
24
  return output["choices"][0]["text"]
25
 
 
1
  import gradio as gr
2
+ from huggingface_hub import hf_hub_download
3
  from llama_cpp import Llama
4
 
5
+ # Téléchargement automatique du modèle depuis Hugging Face Hub
6
+ model_path = hf_hub_download(
7
+ repo_id="google/gemma-2b-it-GGUF",
8
+ filename="gemma-2b-it-Q4_K_M.gguf",
9
+ cache_dir="./model_cache" # dossier local pour stocker le modèle
10
+ )
11
 
12
+ # Chargement du modèle en CPU
13
  llm = Llama(model_path=model_path, n_ctx=2048, n_threads=2)
14
 
15
  def chatbot(message, history):
 
22
  "Ne fais pas de diagnostic médical et précise toujours que l'utilisateur doit consulter "
23
  "un médecin pour tout problème grave. Réponds avec bienveillance et clarté.\n\n"
24
  )
25
+
26
  for human, bot in history:
27
  prompt += f"Utilisateur: {human}\nAssistant: {bot}\n"
28
  prompt += f"Utilisateur: {message}\nAssistant:"
29
+
30
  output = llm(prompt, max_tokens=300)
31
  return output["choices"][0]["text"]
32