adrien.aribaut-gaudin
commited on
Commit
•
4955081
1
Parent(s):
498db6b
feat: added the reading of the excel file, and the possibility to download a copy of the file.
Browse files- config.py +1 -0
- src/control/controller.py +26 -4
- src/tools/excel_tools.py +5 -0
- src/view/view.py +34 -4
- temp/requirements_file/file.txt +0 -0
config.py
CHANGED
@@ -7,6 +7,7 @@ config = {
|
|
7 |
'default_template_index': 0,
|
8 |
'styled_docs_path': 'temp/styles_files',
|
9 |
'generated_docs_path': 'temp/generated_files',
|
|
|
10 |
'options': ["Recentrer les tableaux", "Justifier le texte (Normal)"],
|
11 |
'max_styles': 300,
|
12 |
'log_msg': {
|
|
|
7 |
'default_template_index': 0,
|
8 |
'styled_docs_path': 'temp/styles_files',
|
9 |
'generated_docs_path': 'temp/generated_files',
|
10 |
+
'excel_doc_path' : 'temp/requirements_file',
|
11 |
'options': ["Recentrer les tableaux", "Justifier le texte (Normal)"],
|
12 |
'max_styles': 300,
|
13 |
'log_msg': {
|
src/control/controller.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import asyncio
|
2 |
import os
|
|
|
3 |
from typing import Dict
|
4 |
import random
|
5 |
import datetime
|
@@ -13,6 +14,7 @@ import src.tools.semantic_db as semantic_db
|
|
13 |
from src.tools.wiki import Wiki
|
14 |
from src.llm.llm_tools import get_wikilist, get_public_paragraph, get_private_paragraph
|
15 |
from src.tools.semantic_db import add_texts_to_collection, query_collection
|
|
|
16 |
import gradio as gr
|
17 |
from src.retriever.retriever import Retriever
|
18 |
|
@@ -22,6 +24,7 @@ class Controller:
|
|
22 |
self.templates_path = config['templates_path']
|
23 |
self.generated_docs_path = config['generated_docs_path']
|
24 |
self.styled_docs_path = config['styled_docs_path']
|
|
|
25 |
self.new_docs = []
|
26 |
self.gen_docs = []
|
27 |
self.input_csv = ""
|
@@ -72,7 +75,9 @@ class Controller:
|
|
72 |
self.gen_docs = []
|
73 |
self.log = []
|
74 |
path_to_clear = os.path.abspath(self.generated_docs_path)
|
|
|
75 |
[os.remove(f"{path_to_clear}/{doc}") for doc in os.listdir(path_to_clear)]
|
|
|
76 |
|
77 |
def set_template(self, template_name: str = ""):
|
78 |
if not template_name:
|
@@ -252,14 +257,14 @@ class Controller:
|
|
252 |
gen_paths = list(set(gen_paths))
|
253 |
return gen_paths
|
254 |
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
|
259 |
|
260 |
"""
|
261 |
Requirements
|
262 |
"""
|
|
|
|
|
|
|
263 |
|
264 |
def set_input_csv(self, csv_path: str):
|
265 |
"""
|
@@ -282,4 +287,21 @@ class Controller:
|
|
282 |
"""
|
283 |
fills the collection with the blocks of the documents
|
284 |
"""
|
285 |
-
Retriever(doc=doc, collection=collection)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import asyncio
|
2 |
import os
|
3 |
+
import shutil
|
4 |
from typing import Dict
|
5 |
import random
|
6 |
import datetime
|
|
|
14 |
from src.tools.wiki import Wiki
|
15 |
from src.llm.llm_tools import get_wikilist, get_public_paragraph, get_private_paragraph
|
16 |
from src.tools.semantic_db import add_texts_to_collection, query_collection
|
17 |
+
from src.tools.excel_tools import excel_to_json
|
18 |
import gradio as gr
|
19 |
from src.retriever.retriever import Retriever
|
20 |
|
|
|
24 |
self.templates_path = config['templates_path']
|
25 |
self.generated_docs_path = config['generated_docs_path']
|
26 |
self.styled_docs_path = config['styled_docs_path']
|
27 |
+
self.excel_doc_path = config['excel_doc_path']
|
28 |
self.new_docs = []
|
29 |
self.gen_docs = []
|
30 |
self.input_csv = ""
|
|
|
75 |
self.gen_docs = []
|
76 |
self.log = []
|
77 |
path_to_clear = os.path.abspath(self.generated_docs_path)
|
78 |
+
second_path_to_clear = os.path.abspath(self.excel_doc_path)
|
79 |
[os.remove(f"{path_to_clear}/{doc}") for doc in os.listdir(path_to_clear)]
|
80 |
+
[os.remove(f"{second_path_to_clear}/{doc}") for doc in os.listdir(second_path_to_clear)]
|
81 |
|
82 |
def set_template(self, template_name: str = ""):
|
83 |
if not template_name:
|
|
|
257 |
gen_paths = list(set(gen_paths))
|
258 |
return gen_paths
|
259 |
|
|
|
|
|
|
|
260 |
|
261 |
|
262 |
"""
|
263 |
Requirements
|
264 |
"""
|
265 |
+
def clear_input_csv(self):
|
266 |
+
self.input_csv = ""
|
267 |
+
[os.remove(f"{self.excel_doc_path}/{doc}") for doc in os.listdir(self.excel_doc_path)]
|
268 |
|
269 |
def set_input_csv(self, csv_path: str):
|
270 |
"""
|
|
|
287 |
"""
|
288 |
fills the collection with the blocks of the documents
|
289 |
"""
|
290 |
+
Retriever(doc=doc, collection=collection)
|
291 |
+
|
292 |
+
def generate_response_to_requirements(self):
|
293 |
+
excel_content = self.get_requirements_from_csv()
|
294 |
+
print(excel_content)
|
295 |
+
excel_name = self.input_csv
|
296 |
+
if '/' in excel_name:
|
297 |
+
excel_name = excel_name.split('/')[-1]
|
298 |
+
elif '\\' in excel_name:
|
299 |
+
excel_name = excel_name.split('\\')[-1]
|
300 |
+
#copy the document and generate the new one
|
301 |
+
shutil.copy(self.input_csv, self.excel_doc_path)
|
302 |
+
|
303 |
+
|
304 |
+
|
305 |
+
def get_requirements_from_csv(self):
|
306 |
+
excel_content = excel_to_json(self.input_csv)
|
307 |
+
return excel_content
|
src/tools/excel_tools.py
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
|
3 |
+
def excel_to_json(file_path):
|
4 |
+
df = pd.read_excel(file_path)
|
5 |
+
return df.to_json(orient='records', force_ascii=False)
|
src/view/view.py
CHANGED
@@ -133,10 +133,10 @@ def run(config: Dict, controller: Controller):
|
|
133 |
"""
|
134 |
|
135 |
with gr.Accordion("Générer la réponse aux exigences (en cours de développement)", open=False, visible=True) as exigences_acc:
|
136 |
-
input_csv_comp = gr.File(file_count=
|
137 |
with gr.Row():
|
138 |
verif_btn = gr.Button("Générer la réponse aux exigences (en cours de développement)", visible=False)
|
139 |
-
output_csv_comp = gr.File(file_count="single", file_types=[".
|
140 |
|
141 |
gr.Markdown("")
|
142 |
gr.Markdown("")
|
@@ -175,8 +175,12 @@ def run(config: Dict, controller: Controller):
|
|
175 |
"""
|
176 |
|
177 |
def input_csv_fn(input_csv_):
|
178 |
-
if
|
179 |
-
raise gr.Error(f'
|
|
|
|
|
|
|
|
|
180 |
else:
|
181 |
controller.set_input_csv(input_csv_)
|
182 |
update_ = {
|
@@ -189,6 +193,32 @@ def run(config: Dict, controller: Controller):
|
|
189 |
inputs=[input_csv_comp],
|
190 |
outputs=[verif_btn],
|
191 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
|
193 |
def input_files_upload_fn(input_files_):
|
194 |
for files in input_files_:
|
|
|
133 |
"""
|
134 |
|
135 |
with gr.Accordion("Générer la réponse aux exigences (en cours de développement)", open=False, visible=True) as exigences_acc:
|
136 |
+
input_csv_comp = gr.File(file_count='multiple', file_types=[".xlsx"], label="Fichier d'exigences (xlsx only)")
|
137 |
with gr.Row():
|
138 |
verif_btn = gr.Button("Générer la réponse aux exigences (en cours de développement)", visible=False)
|
139 |
+
output_csv_comp = gr.File(file_count="single", file_types=[".xlsx"], visible=False)
|
140 |
|
141 |
gr.Markdown("")
|
142 |
gr.Markdown("")
|
|
|
175 |
"""
|
176 |
|
177 |
def input_csv_fn(input_csv_):
|
178 |
+
if len(input_csv_) > 1:
|
179 |
+
raise gr.Error(f'Please upload only one file')
|
180 |
+
else:
|
181 |
+
input_csv_ = input_csv_[0]
|
182 |
+
if not input_csv_.name.endswith('.xlsx'):
|
183 |
+
raise gr.Error(f'File {input_csv_.name} is not a xlsx file, please upload only xlsx files')
|
184 |
else:
|
185 |
controller.set_input_csv(input_csv_)
|
186 |
update_ = {
|
|
|
193 |
inputs=[input_csv_comp],
|
194 |
outputs=[verif_btn],
|
195 |
)
|
196 |
+
|
197 |
+
def input_csv_clear_fn():
|
198 |
+
controller.clear_input_csv()
|
199 |
+
update_ = {
|
200 |
+
verif_btn: gr.update(visible=False),
|
201 |
+
}
|
202 |
+
return update_
|
203 |
+
|
204 |
+
input_csv_comp.clear(
|
205 |
+
input_csv_clear_fn,
|
206 |
+
inputs=[],
|
207 |
+
outputs=[verif_btn]
|
208 |
+
)
|
209 |
+
|
210 |
+
def generate_requirements_excel():
|
211 |
+
controller.generate_response_to_requirements()
|
212 |
+
output_path = [f"{controller.excel_doc_path}/{f}" for f in os.listdir(controller.excel_doc_path)]
|
213 |
+
update_ = {
|
214 |
+
output_csv_comp: gr.update(value=output_path, visible=True),
|
215 |
+
}
|
216 |
+
return update_
|
217 |
+
|
218 |
+
verif_btn.click(generate_requirements_excel,
|
219 |
+
inputs=[],
|
220 |
+
outputs=[output_csv_comp],
|
221 |
+
)
|
222 |
|
223 |
def input_files_upload_fn(input_files_):
|
224 |
for files in input_files_:
|
temp/requirements_file/file.txt
ADDED
File without changes
|