Spaces:
Sleeping
Sleeping
Commit
·
d78dcaa
1
Parent(s):
61ca6f5
Clean up, moved prompt to textbox
Browse files
app.py
CHANGED
@@ -2,28 +2,13 @@ import gradio as gr
|
|
2 |
from huggingface_hub import login, InferenceClient
|
3 |
import os
|
4 |
from langchain_community.vectorstores import FAISS
|
5 |
-
from
|
6 |
|
7 |
HF_TOKEN = os.getenv("HUGGINGFACE_TOKEN")
|
8 |
|
9 |
login(token=HF_TOKEN)
|
10 |
client = InferenceClient(token=HF_TOKEN)
|
11 |
|
12 |
-
system_message = """Tu es un assistant juridique spécialisé dans le Code de l'éducation français.
|
13 |
-
Ta mission est d'aider les utilisateurs à comprendre la législation en répondant à leurs questions.
|
14 |
-
|
15 |
-
Voici comment tu dois procéder :
|
16 |
-
|
17 |
-
1. **Analyse de la question:** Lis attentivement la question de l'utilisateur.
|
18 |
-
2. **Identification des articles pertinents:** Examine les 10 articles de loi fournis et sélectionne ceux qui sont les plus pertinents pour répondre à la question.
|
19 |
-
3. **Formulation de la réponse:** Rédige une réponse claire et concise en français, en utilisant les informations des articles sélectionnés. Cite explicitement les articles que tu utilises (par exemple, "Selon l'article L311-3...").
|
20 |
-
4. **Structure de la réponse:** Si ta réponse s'appuie sur plusieurs articles, structure-la de manière logique, en séparant les informations provenant de chaque article.
|
21 |
-
5. **Cas ambigus:**
|
22 |
-
* Si la question est trop vague, demande des précisions à l'utilisateur.
|
23 |
-
* Si plusieurs articles pourraient s'appliquer, présente les différentes
|
24 |
-
interprétations possibles."""
|
25 |
-
|
26 |
-
|
27 |
|
28 |
embeddings = HuggingFaceEmbeddings(model_name="OrdalieTech/Solon-embeddings-large-0.1")
|
29 |
|
@@ -45,7 +30,7 @@ Voici comment tu dois procéder :
|
|
45 |
* Si plusieurs articles pourraient s'appliquer, présente les différentes interprétations possibles."""
|
46 |
|
47 |
|
48 |
-
def query_rag(query, model):
|
49 |
docs = db_code.similarity_search(query, 10)
|
50 |
|
51 |
article_dict = {}
|
@@ -75,8 +60,8 @@ def create_context_response(response, article_dict):
|
|
75 |
|
76 |
return response
|
77 |
|
78 |
-
def chat_interface(query, model):
|
79 |
-
response, article_dict = query_rag(query, model)
|
80 |
response_with_context = create_context_response(response, article_dict)
|
81 |
return response_with_context
|
82 |
|
@@ -104,14 +89,16 @@ with gr.Blocks(title="Assistant Juridique pour le Code de l'éducation (Beta)")
|
|
104 |
"NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
|
105 |
"mistralai/Mixtral-8x22B-v0.1"
|
106 |
],
|
107 |
-
value="
|
108 |
|
109 |
submit_button = gr.Button("Envoyer")
|
110 |
|
111 |
response_box = gr.Markdown()
|
112 |
|
|
|
|
|
113 |
submit_button.click(chat_interface,
|
114 |
-
inputs=[query_box, model],
|
115 |
outputs=[response_box])
|
116 |
|
117 |
demo.launch()
|
|
|
2 |
from huggingface_hub import login, InferenceClient
|
3 |
import os
|
4 |
from langchain_community.vectorstores import FAISS
|
5 |
+
from langchain_community.embeddings import HuggingFaceEmbeddings
|
6 |
|
7 |
HF_TOKEN = os.getenv("HUGGINGFACE_TOKEN")
|
8 |
|
9 |
login(token=HF_TOKEN)
|
10 |
client = InferenceClient(token=HF_TOKEN)
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
embeddings = HuggingFaceEmbeddings(model_name="OrdalieTech/Solon-embeddings-large-0.1")
|
14 |
|
|
|
30 |
* Si plusieurs articles pourraient s'appliquer, présente les différentes interprétations possibles."""
|
31 |
|
32 |
|
33 |
+
def query_rag(query, model, system_prompt):
|
34 |
docs = db_code.similarity_search(query, 10)
|
35 |
|
36 |
article_dict = {}
|
|
|
60 |
|
61 |
return response
|
62 |
|
63 |
+
def chat_interface(query, model, system_prompt):
|
64 |
+
response, article_dict = query_rag(query, model, system_prompt)
|
65 |
response_with_context = create_context_response(response, article_dict)
|
66 |
return response_with_context
|
67 |
|
|
|
89 |
"NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
|
90 |
"mistralai/Mixtral-8x22B-v0.1"
|
91 |
],
|
92 |
+
value="meta-llama/Meta-Llama-3-70B-Instruct")
|
93 |
|
94 |
submit_button = gr.Button("Envoyer")
|
95 |
|
96 |
response_box = gr.Markdown()
|
97 |
|
98 |
+
system_box = gr.Textbox(label="Invite systeme", value=system_prompt)
|
99 |
+
|
100 |
submit_button.click(chat_interface,
|
101 |
+
inputs=[query_box, model, system_box],
|
102 |
outputs=[response_box])
|
103 |
|
104 |
demo.launch()
|