rkonan commited on
Commit
6a4f05e
·
0 Parent(s):

premier commit

Browse files
Files changed (3) hide show
  1. .gitignore +6 -0
  2. app.py +32 -0
  3. main.py +10 -0
.gitignore ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ # Fichiers et dossiers à ignorer
2
+ llamavenv/
3
+ models/
4
+ *.gguf
5
+ __pycache__/
6
+ *.pyc
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from llama_cpp import Llama
3
+ import os
4
+
5
+ st.set_page_config(page_title="Chatbot RAG local",page_icon="🤖")
6
+
7
+ @st.cache_resource
8
+ def load_model():
9
+ model_path="models/phi-2.Q4_K_M.gguf"
10
+ if not os.path.exists(model_path):
11
+ raise FileNotFoundError(f"Modèle non trouvé: {model_path}")
12
+ return Llama(model_path=model_path,n_ctx=2048,n_threads=4)
13
+
14
+ llm=load_model()
15
+
16
+ st.title("🤖 Chatbot LLM Local (CPU)")
17
+
18
+ user_input=st.text_area("Posez votre question :", height=100)
19
+
20
+ if st.button("Envoyer") and user_input.strip():
21
+ with st.spinner("Génération en cours..."):
22
+ full_prompt = f"### Instruction: {user_input.strip()}\n### Réponse:"
23
+ #full_prompt = f"Question: {user_input.strip()}\nAnswer:"
24
+ #output = llm(full_prompt, max_tokens=100, stop=["Question:", "Answer:", "\n\n"])
25
+ output = llm(full_prompt, max_tokens=150, stop=["### Instruction:"])
26
+ #output = llm(full_prompt, max_tokens=80)
27
+ #response = output["choices"][0]["text"]
28
+ response = output["choices"][0]["text"].strip()
29
+ response = response.split("### Instruction:")[0].strip()
30
+
31
+ st.markdown("**Réponse :**")
32
+ st.success(response)
main.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ from llama_cpp import Llama
2
+
3
+ llm = Llama(
4
+ model_path="models/Nous-Hermes-2-Mistral-7B-DPO.Q4_K_M.gguf", # ajuste le chemin si nécessaire
5
+ n_ctx=2048,
6
+ n_threads=4
7
+ )
8
+
9
+ response = llm("### Instruction: Quelle est la capitale du Sénégal ?\n### Réponse:", max_tokens=128)
10
+ print(response["choices"][0]["text"])