changes to struct
Browse files- app.py +1 -1
- src/app.py +0 -91
- src/app2.py +0 -16
- src/control/control.py +2 -8
- src/control2.py +0 -36
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
|
4 |
-
import src.control as ctrl
|
5 |
|
6 |
|
7 |
"""
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
|
4 |
+
import src.control.control as ctrl
|
5 |
|
6 |
|
7 |
"""
|
src/app.py
DELETED
@@ -1,91 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
|
3 |
-
|
4 |
-
import src.control as ctrl
|
5 |
-
|
6 |
-
|
7 |
-
"""
|
8 |
-
==================================
|
9 |
-
A. Component part
|
10 |
-
==================================
|
11 |
-
"""
|
12 |
-
|
13 |
-
with gr.Blocks() as hrqa:
|
14 |
-
|
15 |
-
with gr.Row():
|
16 |
-
|
17 |
-
with gr.Column():
|
18 |
-
pass
|
19 |
-
|
20 |
-
with gr.Column(scale=10):
|
21 |
-
"""
|
22 |
-
1. input docs components
|
23 |
-
"""
|
24 |
-
|
25 |
-
gr.Markdown("# Questions sur le vivre ensemble en entreprise")
|
26 |
-
|
27 |
-
input_text_comp = gr.Textbox(
|
28 |
-
label="",
|
29 |
-
lines=1,
|
30 |
-
max_lines=3,
|
31 |
-
interactive=True,
|
32 |
-
placeholder="Posez votre question ici",
|
33 |
-
)
|
34 |
-
input_example_comp = gr.Radio(
|
35 |
-
label="Examples de questions",
|
36 |
-
choices=["Remboursement de frais de voiture", "Recommandations de transport"],
|
37 |
-
)
|
38 |
-
output_text_comp = gr.Textbox(
|
39 |
-
label="La réponse automatique",
|
40 |
-
lines=2,
|
41 |
-
max_lines=10,
|
42 |
-
interactive=False,
|
43 |
-
visible=False,
|
44 |
-
)
|
45 |
-
sources_comp = gr.CheckboxGroup(
|
46 |
-
label="Documents sources",
|
47 |
-
visible=False,
|
48 |
-
interactive=False,
|
49 |
-
)
|
50 |
-
|
51 |
-
with gr.Column():
|
52 |
-
pass
|
53 |
-
|
54 |
-
|
55 |
-
def input_text_fn1():
|
56 |
-
update_ = {
|
57 |
-
output_text_comp: gr.update(visible=True),
|
58 |
-
}
|
59 |
-
return update_
|
60 |
-
|
61 |
-
def input_text_fn2(input_text_):
|
62 |
-
answer, sources = ctrl.get_response(query=input_text_)
|
63 |
-
source_labels = [s['distance']+' '+s['paragraph']+' '+s['title']+' from '+s['doc'] for s in sources]
|
64 |
-
update_ = {
|
65 |
-
output_text_comp: gr.update(value=answer),
|
66 |
-
sources_comp: gr.update(visible=True, choices=source_labels, value=source_labels)
|
67 |
-
}
|
68 |
-
return update_
|
69 |
-
|
70 |
-
|
71 |
-
def input_example_fn(input_example_):
|
72 |
-
examples = {
|
73 |
-
"Remboursement de frais de voiture": "Comment sont remboursés mes frais kilométriques sur mes trajets "
|
74 |
-
"professionnels?",
|
75 |
-
"Recommandations de transport": "Quelles sont les recommandations de l'entreprise? Vaut-il mieux voyager en "
|
76 |
-
"train ou en avion?"
|
77 |
-
}
|
78 |
-
update_ = {
|
79 |
-
input_text_comp: gr.update(value=examples[input_example_]),
|
80 |
-
output_text_comp: gr.update(visible=True),
|
81 |
-
}
|
82 |
-
return update_
|
83 |
-
|
84 |
-
input_text_comp\
|
85 |
-
.submit(input_text_fn1, inputs=[], outputs=[output_text_comp])\
|
86 |
-
.then(input_text_fn2, inputs=[input_text_comp], outputs=[output_text_comp, sources_comp])
|
87 |
-
input_example_comp\
|
88 |
-
.change(input_example_fn, inputs=[input_example_comp], outputs=[input_text_comp, output_text_comp])\
|
89 |
-
.then(input_text_fn2, inputs=[input_text_comp], outputs=[output_text_comp, sources_comp])
|
90 |
-
|
91 |
-
hrqa.queue().launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/app2.py
DELETED
@@ -1,16 +0,0 @@
|
|
1 |
-
from langchain.agents import create_csv_agent
|
2 |
-
from langchain.agents import create_pandas_dataframe_agent
|
3 |
-
import src.tools.llm as llm
|
4 |
-
|
5 |
-
import pandas as pd
|
6 |
-
|
7 |
-
path = '../data/AccomodationAndMealsForfaits_en.csv'
|
8 |
-
#path = '../data/test_utf32.csv'
|
9 |
-
df = pd.read_csv(path, encoding='utf32', sep=";")
|
10 |
-
agent = create_pandas_dataframe_agent(llm.OpenAI(temperature=0), df, verbose=True)
|
11 |
-
refund = agent.run("Quel est le remboursement pour un repas en Turkiye?")
|
12 |
-
print(refund)
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/control/control.py
CHANGED
@@ -8,8 +8,8 @@ chroma_client = chromadb.Client()
|
|
8 |
|
9 |
plan_language = 'en'
|
10 |
content_language = 'en'
|
11 |
-
path_plan = '
|
12 |
-
path_content = '
|
13 |
collection_name = "until_9"
|
14 |
|
15 |
doc_plan = Doc(path_plan)
|
@@ -41,9 +41,3 @@ def select_best_sources(sources: [], delta_1_2=0.1, delta_1_n=0.25, absolute=1.1
|
|
41 |
return best_sources
|
42 |
|
43 |
|
44 |
-
q1 = "Comment sont remboursés mes frais kilométriques sur mes déplacements avec mon véhicule personnel?"
|
45 |
-
q2 = "Quels sont les moyens de transport recommandés par la société?"
|
46 |
-
q3 = "est-ce que mes billets de cinéma peuvent être remboursés?"
|
47 |
-
|
48 |
-
a2 = get_response(q3)
|
49 |
-
print(a2)
|
|
|
8 |
|
9 |
plan_language = 'en'
|
10 |
content_language = 'en'
|
11 |
+
path_plan = 'data/business_trips_plan_until_9_en.docx'
|
12 |
+
path_content = 'data/business_trips_content_until_9_en.docx'
|
13 |
collection_name = "until_9"
|
14 |
|
15 |
doc_plan = Doc(path_plan)
|
|
|
41 |
return best_sources
|
42 |
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
src/control2.py
DELETED
@@ -1,36 +0,0 @@
|
|
1 |
-
from langchain.agents import AgentType, initialize_agent
|
2 |
-
from langchain.tools import BaseTool, StructuredTool, Tool, tool
|
3 |
-
|
4 |
-
|
5 |
-
from src.control import *
|
6 |
-
|
7 |
-
|
8 |
-
@tool
|
9 |
-
def similarity_search(query: str) -> str:
|
10 |
-
"""
|
11 |
-
useful for when you look for relevant content about business trip policy : transport, accomodation, etc.
|
12 |
-
"""
|
13 |
-
query = llm.translate(query)
|
14 |
-
sources = rtrvr.similarity_search(collection=collection_, query=query)
|
15 |
-
sources = select_best_sources(sources)
|
16 |
-
sources_contents = [s['content'] for s in sources]
|
17 |
-
context = '\n'.join(sources_contents)
|
18 |
-
return context
|
19 |
-
|
20 |
-
|
21 |
-
@tool
|
22 |
-
def generate_answer(query_and_context: str) -> str:
|
23 |
-
"""
|
24 |
-
useful for when you have a query and the relevant content to generate an answer
|
25 |
-
"""
|
26 |
-
answer = llm.generate_paragraph2(query_and_context=query_and_context, language='en')
|
27 |
-
answer = llm.translate(text=answer, language='fr')
|
28 |
-
return answer.lstrip()
|
29 |
-
|
30 |
-
|
31 |
-
tools = [similarity_search, generate_answer]
|
32 |
-
|
33 |
-
agent = initialize_agent(tools, llm.openai_llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
|
34 |
-
q1 = "Comment sont remboursés mes frais kilométriques sur mes déplacements avec mon véhicule personnel?"
|
35 |
-
q2 = "Quels sont les moyens de transport recommandés par la société?"
|
36 |
-
ans = agent.run(q2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|