rkonan commited on
Commit
236b637
·
1 Parent(s): e7a5765

reorganisation

Browse files
Files changed (28) hide show
  1. app.py +76 -59
  2. app_ollama_v1.py +0 -108
  3. rag_model_ollama_v1.py → rag_model_ollama.py +0 -0
  4. sauve/app_old.py +91 -0
  5. app_ollama_v1 copy 2.py → sauve/app_ollama_v1 copy 2.py +0 -0
  6. app_ollama_v1 copy.py → sauve/app_ollama_v1 copy.py +0 -0
  7. app_ollama_v1_chat.py → sauve/app_ollama_v1_chat.py +0 -0
  8. log_app.txt → sauve/log_app.txt +0 -0
  9. log_cli.txt → sauve/log_cli.txt +0 -0
  10. logs → sauve/logs +0 -0
  11. rag_model.py → sauve/rag_model.py +0 -0
  12. rag_model_ollama_v1 copy 2.py → sauve/rag_model_ollama_v1 copy 2.py +0 -0
  13. rag_model_ollama_v1 copy.py → sauve/rag_model_ollama_v1 copy.py +0 -0
  14. rag_model_ollama_v1 stable_lazy.py → sauve/rag_model_ollama_v1 stable_lazy.py +0 -0
  15. rag_model_ollama_v1_ok_full_load.py → sauve/rag_model_ollama_v1_ok_full_load.py +0 -0
  16. rag_model_ollama_v1_ok_llm.py → sauve/rag_model_ollama_v1_ok_llm.py +0 -0
  17. rag_model_ollama_v2.py → sauve/rag_model_ollama_v2.py +0 -0
  18. rag_model_optimise.py → sauve/rag_model_optimise.py +0 -0
  19. requirements-base.txt → sauve/requirements-base.txt +0 -0
  20. requirements._extendedtxt → sauve/requirements._extendedtxt +0 -0
  21. step1_read_pdf.py → sauve/step1_read_pdf.py +0 -0
  22. step2_chunk.py → sauve/step2_chunk.py +0 -0
  23. step3_embed.py → sauve/step3_embed.py +0 -0
  24. step3_llamaindex.py → sauve/step3_llamaindex.py +0 -0
  25. step3_llamaindex_evol.py → sauve/step3_llamaindex_evol.py +0 -0
  26. step4_faiss.py → sauve/step4_faiss.py +0 -0
  27. step4b_shell.py → sauve/step4b_shell.py +0 -0
  28. tester.py → sauve/tester.py +0 -0
app.py CHANGED
@@ -1,91 +1,108 @@
1
- import streamlit as st
2
- from llama_cpp import Llama
3
- import os
4
- from rag_model import RAGEngine
5
-
6
- #from rag_model_optimise import RAGEngine
7
  import logging
 
8
  from huggingface_hub import hf_hub_download
9
- import time
10
-
11
 
12
- import os
13
- os.environ["NLTK_DATA"] = "/home/appuser/nltk_data"
14
 
15
- # Appliquer le patch avant tout import de llama_index
16
- from patches.llama_patch import patch_llamaindex_nltk
17
- patch_llamaindex_nltk()
18
 
19
  logger = logging.getLogger("Streamlit")
20
  logger.setLevel(logging.INFO)
21
  handler = logging.StreamHandler()
22
  formatter = logging.Formatter("[%(asctime)s] %(levelname)s - %(message)s")
23
  handler.setFormatter(formatter)
24
- logger.addHandler(handler)
25
-
26
 
27
- ENV = os.getenv("ENV", "space")
28
- logger.info(f"ENV :{ENV}")
29
 
30
- #time.sleep(5)
 
 
31
 
 
32
  if ENV == "local":
33
- model_path = "chatbot-models/Nous-Hermes-2-Mistral-7B-DPO.Q4_K_M.gguf"
34
- faiss_index_path="chatbot-models/vectordb_docling/index.faiss"
35
- vectors_path="chatbot-models/vectordb_docling/chunks.pkl"
36
-
37
  else:
38
- # Télécharger le modèle GGUF
39
- model_path = hf_hub_download(
40
- repo_id="rkonan/chatbot-models",
41
- filename="chatbot-models/Nous-Hermes-2-Mistral-7B-DPO.Q4_K_M.gguf",
42
- repo_type="dataset"
43
- )
44
-
45
- # Télécharger les fichiers FAISS
46
  faiss_index_path = hf_hub_download(
47
  repo_id="rkonan/chatbot-models",
48
  filename="chatbot-models/vectordb_docling/index.faiss",
49
  repo_type="dataset"
50
  )
51
-
52
  vectors_path = hf_hub_download(
53
  repo_id="rkonan/chatbot-models",
54
  filename="chatbot-models/vectordb_docling/chunks.pkl",
55
  repo_type="dataset"
56
  )
57
 
58
-
59
-
60
-
61
- st.set_page_config(page_title="Chatbot RAG local",page_icon="🤖")
62
-
63
-
64
-
65
-
66
-
67
- @st.cache_resource
68
- def load_rag_engine():
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  rag = RAGEngine(
70
- model_path=model_path,
71
  vector_path=vectors_path,
72
  index_path=faiss_index_path,
73
- model_threads=8 # ✅ plus rapide
 
 
74
  )
75
-
76
- # 🔥 Warmup pour éviter latence au 1er appel
77
- rag.llm("Bonjour", max_tokens=1)
78
  return rag
79
 
80
-
81
- rag=load_rag_engine()
82
-
83
- st.title("🤖 Chatbot LLM Local (CPU)")
84
-
85
- user_input=st.text_area("Posez votre question :", height=100)
86
-
87
- if st.button("Envoyer") and user_input.strip():
88
- with st.spinner("Génération en cours..."):
89
- response = rag.ask(user_input)
90
- st.markdown("**Réponse :**")
91
- st.success(response)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
 
 
 
 
 
2
  import logging
3
+ import streamlit as st
4
  from huggingface_hub import hf_hub_download
 
 
5
 
6
+ # ✅ Nouveau moteur RAG (sans ollama_opts)
7
+ from rag_model_ollama_v1 import RAGEngine
8
 
9
+ # --- Config & logs ---
10
+ os.environ.setdefault("NLTK_DATA", "/home/appuser/nltk_data")
 
11
 
12
  logger = logging.getLogger("Streamlit")
13
  logger.setLevel(logging.INFO)
14
  handler = logging.StreamHandler()
15
  formatter = logging.Formatter("[%(asctime)s] %(levelname)s - %(message)s")
16
  handler.setFormatter(formatter)
17
+ if not logger.handlers:
18
+ logger.addHandler(handler)
19
 
20
+ st.set_page_config(page_title="Chatbot RAG (Ollama)", page_icon="🤖")
 
21
 
22
+ # --- ENV ---
23
+ ENV = os.getenv("ENV", "local")
24
+ logger.info(f"ENV: {ENV}")
25
 
26
+ # --- Chemins FAISS & chunks ---
27
  if ENV == "local":
28
+ faiss_index_path = "chatbot-models/vectordb_docling/index.faiss"
29
+ vectors_path = "chatbot-models/vectordb_docling/chunks.pkl"
 
 
30
  else:
 
 
 
 
 
 
 
 
31
  faiss_index_path = hf_hub_download(
32
  repo_id="rkonan/chatbot-models",
33
  filename="chatbot-models/vectordb_docling/index.faiss",
34
  repo_type="dataset"
35
  )
 
36
  vectors_path = hf_hub_download(
37
  repo_id="rkonan/chatbot-models",
38
  filename="chatbot-models/vectordb_docling/chunks.pkl",
39
  repo_type="dataset"
40
  )
41
 
42
+ # --- UI Sidebar ---
43
+ st.sidebar.header("⚙️ Paramètres")
44
+ default_host = os.getenv("OLLAMA_HOST", "http://localhost:11435")
45
+ ollama_host = st.sidebar.text_input("Ollama host", value=default_host)
46
+ suggested_models = [
47
+ "qwen2.5:3b-instruct-q4_K_M",
48
+ "noushermes_rag",
49
+ "mistral",
50
+ "gemma3",
51
+ "deepseek-r1",
52
+ "granite3.3",
53
+ "llama3.1:8b-instruct-q4_K_M",
54
+ "nous-hermes2:Q4_K_M",
55
+ ]
56
+ model_name = st.sidebar.selectbox("Modèle Ollama", options=suggested_models, index=0)
57
+ num_threads = st.sidebar.slider("Threads (hint)", min_value=2, max_value=16, value=6, step=1)
58
+ temperature = st.sidebar.slider("Température", min_value=0.0, max_value=1.5, value=0.1, step=0.1)
59
+
60
+ st.title("🤖 Chatbot RAG Local (Ollama)")
61
+
62
+ # --- Cache du moteur ---
63
+ @st.cache_resource(show_spinner=True)
64
+ def load_rag_engine(_model_name: str, _host: str, _threads: int, _temp: float):
65
+ os.environ["OLLAMA_KEEP_ALIVE"] = "15m"
66
  rag = RAGEngine(
67
+ model_name=_model_name,
68
  vector_path=vectors_path,
69
  index_path=faiss_index_path,
70
+ model_threads=_threads,
71
+ ollama_host=_host
72
+ # ❌ pas d'ollama_opts → Ollama choisit les defaults
73
  )
 
 
 
74
  return rag
75
 
76
+ rag = load_rag_engine(model_name, ollama_host, num_threads, temperature)
77
+
78
+ # --- Chat simple ---
79
+ user_input = st.text_area("Posez votre question :", height=120,
80
+ placeholder="Ex: Quels sont les traitements appliqués aux images ?")
81
+ col1, col2 = st.columns([1, 1])
82
+
83
+ # if col1.button("Envoyer"):
84
+ # if user_input.strip():
85
+ # with st.spinner("Génération en cours..."):
86
+ # try:
87
+ # response = rag.ask(user_input)
88
+ # st.markdown("**Réponse :**")
89
+ # st.success(response)
90
+ # except Exception as e:
91
+ # st.error(f"Erreur pendant la génération: {e}")
92
+ # else:
93
+ # st.info("Saisissez une question.")
94
+
95
+ if col2.button("Envoyer (stream)"):
96
+ if user_input.strip():
97
+ with st.spinner("Génération en cours (stream)..."):
98
+ try:
99
+ ph = st.empty()
100
+ acc = ""
101
+ for token in rag.ask_stream(user_input):
102
+ acc += token
103
+ ph.markdown(acc)
104
+ st.balloons()
105
+ except Exception as e:
106
+ st.error(f"Erreur pendant la génération (stream): {e}")
107
+ else:
108
+ st.info("Saisissez une question.")
app_ollama_v1.py DELETED
@@ -1,108 +0,0 @@
1
- import os
2
- import logging
3
- import streamlit as st
4
- from huggingface_hub import hf_hub_download
5
-
6
- # ✅ Nouveau moteur RAG (sans ollama_opts)
7
- from rag_model_ollama_v1 import RAGEngine
8
-
9
- # --- Config & logs ---
10
- os.environ.setdefault("NLTK_DATA", "/home/appuser/nltk_data")
11
-
12
- logger = logging.getLogger("Streamlit")
13
- logger.setLevel(logging.INFO)
14
- handler = logging.StreamHandler()
15
- formatter = logging.Formatter("[%(asctime)s] %(levelname)s - %(message)s")
16
- handler.setFormatter(formatter)
17
- if not logger.handlers:
18
- logger.addHandler(handler)
19
-
20
- st.set_page_config(page_title="Chatbot RAG (Ollama)", page_icon="🤖")
21
-
22
- # --- ENV ---
23
- ENV = os.getenv("ENV", "local")
24
- logger.info(f"ENV: {ENV}")
25
-
26
- # --- Chemins FAISS & chunks ---
27
- if ENV == "local":
28
- faiss_index_path = "chatbot-models/vectordb_docling/index.faiss"
29
- vectors_path = "chatbot-models/vectordb_docling/chunks.pkl"
30
- else:
31
- faiss_index_path = hf_hub_download(
32
- repo_id="rkonan/chatbot-models",
33
- filename="chatbot-models/vectordb_docling/index.faiss",
34
- repo_type="dataset"
35
- )
36
- vectors_path = hf_hub_download(
37
- repo_id="rkonan/chatbot-models",
38
- filename="chatbot-models/vectordb_docling/chunks.pkl",
39
- repo_type="dataset"
40
- )
41
-
42
- # --- UI Sidebar ---
43
- st.sidebar.header("⚙️ Paramètres")
44
- default_host = os.getenv("OLLAMA_HOST", "http://localhost:11435")
45
- ollama_host = st.sidebar.text_input("Ollama host", value=default_host)
46
- suggested_models = [
47
- "qwen2.5:3b-instruct-q4_K_M",
48
- "noushermes_rag",
49
- "mistral",
50
- "gemma3",
51
- "deepseek-r1",
52
- "granite3.3",
53
- "llama3.1:8b-instruct-q4_K_M",
54
- "nous-hermes2:Q4_K_M",
55
- ]
56
- model_name = st.sidebar.selectbox("Modèle Ollama", options=suggested_models, index=0)
57
- num_threads = st.sidebar.slider("Threads (hint)", min_value=2, max_value=16, value=6, step=1)
58
- temperature = st.sidebar.slider("Température", min_value=0.0, max_value=1.5, value=0.1, step=0.1)
59
-
60
- st.title("🤖 Chatbot RAG Local (Ollama)")
61
-
62
- # --- Cache du moteur ---
63
- @st.cache_resource(show_spinner=True)
64
- def load_rag_engine(_model_name: str, _host: str, _threads: int, _temp: float):
65
- os.environ["OLLAMA_KEEP_ALIVE"] = "15m"
66
- rag = RAGEngine(
67
- model_name=_model_name,
68
- vector_path=vectors_path,
69
- index_path=faiss_index_path,
70
- model_threads=_threads,
71
- ollama_host=_host
72
- # ❌ pas d'ollama_opts → Ollama choisit les defaults
73
- )
74
- return rag
75
-
76
- rag = load_rag_engine(model_name, ollama_host, num_threads, temperature)
77
-
78
- # --- Chat simple ---
79
- user_input = st.text_area("Posez votre question :", height=120,
80
- placeholder="Ex: Quels sont les traitements appliqués aux images ?")
81
- col1, col2 = st.columns([1, 1])
82
-
83
- # if col1.button("Envoyer"):
84
- # if user_input.strip():
85
- # with st.spinner("Génération en cours..."):
86
- # try:
87
- # response = rag.ask(user_input)
88
- # st.markdown("**Réponse :**")
89
- # st.success(response)
90
- # except Exception as e:
91
- # st.error(f"Erreur pendant la génération: {e}")
92
- # else:
93
- # st.info("Saisissez une question.")
94
-
95
- if col2.button("Envoyer (stream)"):
96
- if user_input.strip():
97
- with st.spinner("Génération en cours (stream)..."):
98
- try:
99
- ph = st.empty()
100
- acc = ""
101
- for token in rag.ask_stream(user_input):
102
- acc += token
103
- ph.markdown(acc)
104
- st.balloons()
105
- except Exception as e:
106
- st.error(f"Erreur pendant la génération (stream): {e}")
107
- else:
108
- st.info("Saisissez une question.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
rag_model_ollama_v1.py → rag_model_ollama.py RENAMED
File without changes
sauve/app_old.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from llama_cpp import Llama
3
+ import os
4
+ from rag_model import RAGEngine
5
+
6
+ #from rag_model_optimise import RAGEngine
7
+ import logging
8
+ from huggingface_hub import hf_hub_download
9
+ import time
10
+
11
+
12
+ import os
13
+ os.environ["NLTK_DATA"] = "/home/appuser/nltk_data"
14
+
15
+ # Appliquer le patch avant tout import de llama_index
16
+ from patches.llama_patch import patch_llamaindex_nltk
17
+ patch_llamaindex_nltk()
18
+
19
+ logger = logging.getLogger("Streamlit")
20
+ logger.setLevel(logging.INFO)
21
+ handler = logging.StreamHandler()
22
+ formatter = logging.Formatter("[%(asctime)s] %(levelname)s - %(message)s")
23
+ handler.setFormatter(formatter)
24
+ logger.addHandler(handler)
25
+
26
+
27
+ ENV = os.getenv("ENV", "space")
28
+ logger.info(f"ENV :{ENV}")
29
+
30
+ #time.sleep(5)
31
+
32
+ if ENV == "local":
33
+ model_path = "chatbot-models/Nous-Hermes-2-Mistral-7B-DPO.Q4_K_M.gguf"
34
+ faiss_index_path="chatbot-models/vectordb_docling/index.faiss"
35
+ vectors_path="chatbot-models/vectordb_docling/chunks.pkl"
36
+
37
+ else:
38
+ # Télécharger le modèle GGUF
39
+ model_path = hf_hub_download(
40
+ repo_id="rkonan/chatbot-models",
41
+ filename="chatbot-models/Nous-Hermes-2-Mistral-7B-DPO.Q4_K_M.gguf",
42
+ repo_type="dataset"
43
+ )
44
+
45
+ # Télécharger les fichiers FAISS
46
+ faiss_index_path = hf_hub_download(
47
+ repo_id="rkonan/chatbot-models",
48
+ filename="chatbot-models/vectordb_docling/index.faiss",
49
+ repo_type="dataset"
50
+ )
51
+
52
+ vectors_path = hf_hub_download(
53
+ repo_id="rkonan/chatbot-models",
54
+ filename="chatbot-models/vectordb_docling/chunks.pkl",
55
+ repo_type="dataset"
56
+ )
57
+
58
+
59
+
60
+
61
+ st.set_page_config(page_title="Chatbot RAG local",page_icon="🤖")
62
+
63
+
64
+
65
+
66
+
67
+ @st.cache_resource
68
+ def load_rag_engine():
69
+ rag = RAGEngine(
70
+ model_path=model_path,
71
+ vector_path=vectors_path,
72
+ index_path=faiss_index_path,
73
+ model_threads=8 # ✅ plus rapide
74
+ )
75
+
76
+ # 🔥 Warmup pour éviter latence au 1er appel
77
+ rag.llm("Bonjour", max_tokens=1)
78
+ return rag
79
+
80
+
81
+ rag=load_rag_engine()
82
+
83
+ st.title("🤖 Chatbot LLM Local (CPU)")
84
+
85
+ user_input=st.text_area("Posez votre question :", height=100)
86
+
87
+ if st.button("Envoyer") and user_input.strip():
88
+ with st.spinner("Génération en cours..."):
89
+ response = rag.ask(user_input)
90
+ st.markdown("**Réponse :**")
91
+ st.success(response)
app_ollama_v1 copy 2.py → sauve/app_ollama_v1 copy 2.py RENAMED
File without changes
app_ollama_v1 copy.py → sauve/app_ollama_v1 copy.py RENAMED
File without changes
app_ollama_v1_chat.py → sauve/app_ollama_v1_chat.py RENAMED
File without changes
log_app.txt → sauve/log_app.txt RENAMED
File without changes
log_cli.txt → sauve/log_cli.txt RENAMED
File without changes
logs → sauve/logs RENAMED
File without changes
rag_model.py → sauve/rag_model.py RENAMED
File without changes
rag_model_ollama_v1 copy 2.py → sauve/rag_model_ollama_v1 copy 2.py RENAMED
File without changes
rag_model_ollama_v1 copy.py → sauve/rag_model_ollama_v1 copy.py RENAMED
File without changes
rag_model_ollama_v1 stable_lazy.py → sauve/rag_model_ollama_v1 stable_lazy.py RENAMED
File without changes
rag_model_ollama_v1_ok_full_load.py → sauve/rag_model_ollama_v1_ok_full_load.py RENAMED
File without changes
rag_model_ollama_v1_ok_llm.py → sauve/rag_model_ollama_v1_ok_llm.py RENAMED
File without changes
rag_model_ollama_v2.py → sauve/rag_model_ollama_v2.py RENAMED
File without changes
rag_model_optimise.py → sauve/rag_model_optimise.py RENAMED
File without changes
requirements-base.txt → sauve/requirements-base.txt RENAMED
File without changes
requirements._extendedtxt → sauve/requirements._extendedtxt RENAMED
File without changes
step1_read_pdf.py → sauve/step1_read_pdf.py RENAMED
File without changes
step2_chunk.py → sauve/step2_chunk.py RENAMED
File without changes
step3_embed.py → sauve/step3_embed.py RENAMED
File without changes
step3_llamaindex.py → sauve/step3_llamaindex.py RENAMED
File without changes
step3_llamaindex_evol.py → sauve/step3_llamaindex_evol.py RENAMED
File without changes
step4_faiss.py → sauve/step4_faiss.py RENAMED
File without changes
step4b_shell.py → sauve/step4b_shell.py RENAMED
File without changes
tester.py → sauve/tester.py RENAMED
File without changes