Update app.py
Browse files
app.py
CHANGED
@@ -25,7 +25,6 @@ from langgraph.checkpoint.memory import MemorySaver
|
|
25 |
from langchain_openai import ChatOpenAI
|
26 |
from langchain_core.messages import HumanMessage, SystemMessage, AIMessage
|
27 |
|
28 |
-
from dash_socketio import DashSocketIO
|
29 |
import dash
|
30 |
from dash.dependencies import Input, Output, State
|
31 |
from dash import Dash, html, dcc, callback, callback_context, ctx, Output, Input, dash_table, State, no_update, _dash_renderer, clientside_callback
|
@@ -39,7 +38,6 @@ from dash_iconify import DashIconify
|
|
39 |
_dash_renderer._set_react_version("18.2.0")
|
40 |
import flask
|
41 |
from flask_login import LoginManager, UserMixin, login_user, current_user, login_required, logout_user
|
42 |
-
from flask_socketio import SocketIO, emit
|
43 |
from datetime import timedelta
|
44 |
|
45 |
from IPython.display import display, HTML
|
@@ -590,7 +588,7 @@ def build_workflow(num_bcc,file,pathname) -> StateGraph:
|
|
590 |
|
591 |
return workflow
|
592 |
|
593 |
-
def init_agent_state(current_url, num,
|
594 |
initial_state: AgentState = {
|
595 |
#"files_list": csv_files[1:], # Tous les fichiers sauf le premier
|
596 |
#"current_file": csv_files[0], # Premier fichier à traiter
|
@@ -624,40 +622,31 @@ def init_agent_state(current_url, num, socket_id, pathname) -> AgentState:
|
|
624 |
if task == "load_and_preprocess":
|
625 |
if key == "current_file":
|
626 |
result += f"Traitement du fichier {taskInfo['current_file']} en cours...\n"
|
627 |
-
|
628 |
-
time.sleep(0.05)
|
629 |
if task == "classify_teachings":
|
630 |
if key == "status":
|
631 |
for key, value in taskInfo['classified_teachings'].items():
|
632 |
result += f"\n\n-**Enseignement classé dans la catégorie '{key}'** : "
|
633 |
-
emit("stream", f"\n\nEnseignement classé dans la catégorie '{key}' : ", namespace="/", to=socket_id)
|
634 |
-
time.sleep(1.0)
|
635 |
for enseignement in value:
|
636 |
result += f"{enseignement}, "
|
637 |
-
|
638 |
-
time.sleep(0.05)
|
639 |
result += f"\n\nTraitement de la tâche : {taskInfo['status']}...\n"
|
640 |
-
|
641 |
-
time.sleep(0.05)
|
642 |
if task == "create_categories":
|
643 |
if key == "status":
|
644 |
result += f"\n\nTraitement de la tâche : {taskInfo['status']}...\n"
|
645 |
-
|
646 |
-
time.sleep(0.05)
|
647 |
if task == "create_learning_situations":
|
648 |
if key == "status":
|
649 |
if taskInfo['learning_situations'].items():
|
650 |
for key, value in taskInfo['learning_situations'].items():
|
651 |
result += f"\n\n-**Situation d'apprentissage créée pour la catégorie '{key}'** : {value}\n"
|
652 |
-
|
653 |
-
time.sleep(1.0)
|
654 |
result += f"\n\nTraitement de la tâche : {taskInfo['status']}...\n"
|
655 |
-
|
656 |
-
time.sleep(0.05)
|
657 |
else:
|
658 |
result += f"\n\nTraitement de la tâche : pas de situations d'apprentissage créées\n"
|
659 |
-
|
660 |
-
time.sleep(0.05)
|
661 |
if task == "create_academic_competencies":
|
662 |
if key == "dataframe":
|
663 |
df = taskInfo['dataframe']
|
@@ -665,20 +654,16 @@ def init_agent_state(current_url, num, socket_id, pathname) -> AgentState:
|
|
665 |
if taskInfo['academic_competencies'].items():
|
666 |
for key, value in taskInfo['academic_competencies'].items():
|
667 |
result += f"\n\n-**Compétence académique créée pour la catégorie '{key}'** : {value}\n"
|
668 |
-
|
669 |
-
time.sleep(1.0)
|
670 |
result += f"\n\nTraitement de la tâche : {taskInfo['status']}...\n"
|
671 |
-
|
672 |
-
time.sleep(0.05)
|
673 |
else:
|
674 |
result += f"\n\nTraitement de la tâche : pas de BCC créés\n"
|
675 |
-
|
676 |
-
time.sleep(0.05)
|
677 |
if task == "export_to_excel_2":
|
678 |
if key == "status":
|
679 |
result += f"\n\nTraitement de la tâche : {taskInfo['status']}...\n"
|
680 |
-
|
681 |
-
time.sleep(0.05)
|
682 |
|
683 |
except Exception as e:
|
684 |
print(f"Erreur lors de l'exécution du workflow: {e}")
|
@@ -766,7 +751,6 @@ app = dash.Dash(__name__, server=server, external_stylesheets=[dmc.styles.ALL, d
|
|
766 |
update_title='Chargement...',
|
767 |
suppress_callback_exceptions=True)
|
768 |
|
769 |
-
socketio = SocketIO(app.server)
|
770 |
# Updating the Flask Server configuration with Secret Key to encrypt the user session cookie
|
771 |
server.config['REMEMBER_COOKIE_DURATION'] = timedelta(seconds=3600)
|
772 |
|
@@ -1259,7 +1243,6 @@ app_page = dmc.MantineProvider(
|
|
1259 |
),
|
1260 |
html.Div(id='output-response', style={"color":"rgb(90, 242, 156)","border-radius":"3px","border":"1px solid rgb(255,255,255)!important","background-color":"rgba(90, 242, 156, 0.2)","padding":"5px"}),
|
1261 |
html.Div(id="notification_wrapper", style={"margin-top":"1rem"}),
|
1262 |
-
DashSocketIO(id='socketio', eventNames=["notification", "stream"]),
|
1263 |
], width=12)
|
1264 |
])
|
1265 |
], className="mt-5")],
|
@@ -1642,7 +1625,6 @@ app_avid_page = dmc.MantineProvider(
|
|
1642 |
),
|
1643 |
html.Div(id='output-response-avid', style={"color":"rgb(156, 242, 242)","border-radius":"3px","border":"1px solid rgb(255,255,255)!important","background-color":"rgba(156, 242, 242, 0.2)","padding":"5px"}),
|
1644 |
html.Div(id="notification_wrapper-avid", style={"margin-top":"1rem"}),
|
1645 |
-
DashSocketIO(id='socketio-avid', eventNames=["notification", "stream"]),
|
1646 |
], width=12)
|
1647 |
])
|
1648 |
], className="mt-5")],
|
@@ -2189,28 +2171,18 @@ def display_page(pathname):
|
|
2189 |
# You could also return a 404 "URL not found" page here
|
2190 |
return view, url
|
2191 |
|
2192 |
-
@socketio.on("connect")
|
2193 |
-
def on_connect():
|
2194 |
-
print("Client connected")
|
2195 |
-
|
2196 |
-
@socketio.on("disconnect")
|
2197 |
-
def on_disconnect():
|
2198 |
-
print("Client disconnected")
|
2199 |
-
|
2200 |
-
|
2201 |
@callback(
|
2202 |
Output("output-response", "children"),
|
2203 |
Output("notification_wrapper", "children", allow_duplicate=True),
|
2204 |
Input("num-bcc", "value"),
|
2205 |
Input("maquette-dropdown", "value"),
|
2206 |
Input("submit-button", "n_clicks"),
|
2207 |
-
State("socketio", "socketId"),
|
2208 |
State("url", "pathname"),
|
2209 |
running=[[Output("output-response", "children"), "", None]],
|
2210 |
prevent_initial_call=True,
|
2211 |
)
|
2212 |
-
def display_status(num, current, n_clicks,
|
2213 |
-
if not n_clicks
|
2214 |
return no_update, []
|
2215 |
|
2216 |
if not current:
|
@@ -2223,7 +2195,7 @@ def display_status(num, current, n_clicks, socket_id, pathname):
|
|
2223 |
current_url = current
|
2224 |
|
2225 |
print(f"Fichier Maquette sélectionné: {current_url}")
|
2226 |
-
agent = init_agent_state(current_url, num,
|
2227 |
try:
|
2228 |
df = agent[0]
|
2229 |
result = agent[1]
|
@@ -2237,13 +2209,12 @@ def display_status(num, current, n_clicks, socket_id, pathname):
|
|
2237 |
Input("num-bcc-avid", "value"),
|
2238 |
Input("maquette-dropdown-avid", "value"),
|
2239 |
Input("submit-button-avid", "n_clicks"),
|
2240 |
-
State("socketio-avid", "socketId"),
|
2241 |
State("url", "pathname"),
|
2242 |
running=[[Output("output-response-avid", "children"), "", None]],
|
2243 |
prevent_initial_call=True,
|
2244 |
)
|
2245 |
-
def display_status(num, current, n_clicks,
|
2246 |
-
if not n_clicks
|
2247 |
return no_update, []
|
2248 |
|
2249 |
if not current:
|
@@ -2257,7 +2228,7 @@ def display_status(num, current, n_clicks, socket_id, pathname):
|
|
2257 |
|
2258 |
print(f"Fichier Maquette sélectionné: {current_url}")
|
2259 |
|
2260 |
-
agent = init_agent_state(current_url, num,
|
2261 |
try:
|
2262 |
df = agent[0]
|
2263 |
result = agent[1]
|
@@ -2268,7 +2239,6 @@ def display_status(num, current, n_clicks, socket_id, pathname):
|
|
2268 |
clientside_callback(
|
2269 |
"""connected => !connected""",
|
2270 |
Output("submit-button", "disabled"),
|
2271 |
-
Input("socketio", "connected"),
|
2272 |
)
|
2273 |
|
2274 |
clientside_callback(
|
@@ -2277,14 +2247,12 @@ clientside_callback(
|
|
2277 |
return notification
|
2278 |
}""",
|
2279 |
Output("notification_wrapper", "children", allow_duplicate=True),
|
2280 |
-
Input("socketio", "data-notification"),
|
2281 |
prevent_initial_call=True,
|
2282 |
)
|
2283 |
|
2284 |
clientside_callback(
|
2285 |
"""(word, text) => text + word""",
|
2286 |
Output("output-response", "children", allow_duplicate=True),
|
2287 |
-
Input("socketio", "data-stream"),
|
2288 |
State("output-response", "children"),
|
2289 |
prevent_initial_call=True,
|
2290 |
)
|
@@ -2292,7 +2260,6 @@ clientside_callback(
|
|
2292 |
clientside_callback(
|
2293 |
"""connected => !connected""",
|
2294 |
Output("submit-button-avid", "disabled"),
|
2295 |
-
Input("socketio-avid", "connected"),
|
2296 |
)
|
2297 |
|
2298 |
clientside_callback(
|
@@ -2301,14 +2268,12 @@ clientside_callback(
|
|
2301 |
return notification
|
2302 |
}""",
|
2303 |
Output("notification_wrapper-avid", "children", allow_duplicate=True),
|
2304 |
-
Input("socketio-avid", "data-notification"),
|
2305 |
prevent_initial_call=True,
|
2306 |
)
|
2307 |
|
2308 |
clientside_callback(
|
2309 |
"""(word, text) => text + word""",
|
2310 |
Output("output-response-avid", "children", allow_duplicate=True),
|
2311 |
-
Input("socketio-avid", "data-stream"),
|
2312 |
State("output-response-avid", "children"),
|
2313 |
prevent_initial_call=True,
|
2314 |
)
|
|
|
25 |
from langchain_openai import ChatOpenAI
|
26 |
from langchain_core.messages import HumanMessage, SystemMessage, AIMessage
|
27 |
|
|
|
28 |
import dash
|
29 |
from dash.dependencies import Input, Output, State
|
30 |
from dash import Dash, html, dcc, callback, callback_context, ctx, Output, Input, dash_table, State, no_update, _dash_renderer, clientside_callback
|
|
|
38 |
_dash_renderer._set_react_version("18.2.0")
|
39 |
import flask
|
40 |
from flask_login import LoginManager, UserMixin, login_user, current_user, login_required, logout_user
|
|
|
41 |
from datetime import timedelta
|
42 |
|
43 |
from IPython.display import display, HTML
|
|
|
588 |
|
589 |
return workflow
|
590 |
|
591 |
+
def init_agent_state(current_url, num, pathname) -> AgentState:
|
592 |
initial_state: AgentState = {
|
593 |
#"files_list": csv_files[1:], # Tous les fichiers sauf le premier
|
594 |
#"current_file": csv_files[0], # Premier fichier à traiter
|
|
|
622 |
if task == "load_and_preprocess":
|
623 |
if key == "current_file":
|
624 |
result += f"Traitement du fichier {taskInfo['current_file']} en cours...\n"
|
625 |
+
|
|
|
626 |
if task == "classify_teachings":
|
627 |
if key == "status":
|
628 |
for key, value in taskInfo['classified_teachings'].items():
|
629 |
result += f"\n\n-**Enseignement classé dans la catégorie '{key}'** : "
|
|
|
|
|
630 |
for enseignement in value:
|
631 |
result += f"{enseignement}, "
|
632 |
+
|
|
|
633 |
result += f"\n\nTraitement de la tâche : {taskInfo['status']}...\n"
|
634 |
+
|
|
|
635 |
if task == "create_categories":
|
636 |
if key == "status":
|
637 |
result += f"\n\nTraitement de la tâche : {taskInfo['status']}...\n"
|
638 |
+
|
|
|
639 |
if task == "create_learning_situations":
|
640 |
if key == "status":
|
641 |
if taskInfo['learning_situations'].items():
|
642 |
for key, value in taskInfo['learning_situations'].items():
|
643 |
result += f"\n\n-**Situation d'apprentissage créée pour la catégorie '{key}'** : {value}\n"
|
644 |
+
|
|
|
645 |
result += f"\n\nTraitement de la tâche : {taskInfo['status']}...\n"
|
646 |
+
|
|
|
647 |
else:
|
648 |
result += f"\n\nTraitement de la tâche : pas de situations d'apprentissage créées\n"
|
649 |
+
|
|
|
650 |
if task == "create_academic_competencies":
|
651 |
if key == "dataframe":
|
652 |
df = taskInfo['dataframe']
|
|
|
654 |
if taskInfo['academic_competencies'].items():
|
655 |
for key, value in taskInfo['academic_competencies'].items():
|
656 |
result += f"\n\n-**Compétence académique créée pour la catégorie '{key}'** : {value}\n"
|
657 |
+
|
|
|
658 |
result += f"\n\nTraitement de la tâche : {taskInfo['status']}...\n"
|
659 |
+
|
|
|
660 |
else:
|
661 |
result += f"\n\nTraitement de la tâche : pas de BCC créés\n"
|
662 |
+
|
|
|
663 |
if task == "export_to_excel_2":
|
664 |
if key == "status":
|
665 |
result += f"\n\nTraitement de la tâche : {taskInfo['status']}...\n"
|
666 |
+
|
|
|
667 |
|
668 |
except Exception as e:
|
669 |
print(f"Erreur lors de l'exécution du workflow: {e}")
|
|
|
751 |
update_title='Chargement...',
|
752 |
suppress_callback_exceptions=True)
|
753 |
|
|
|
754 |
# Updating the Flask Server configuration with Secret Key to encrypt the user session cookie
|
755 |
server.config['REMEMBER_COOKIE_DURATION'] = timedelta(seconds=3600)
|
756 |
|
|
|
1243 |
),
|
1244 |
html.Div(id='output-response', style={"color":"rgb(90, 242, 156)","border-radius":"3px","border":"1px solid rgb(255,255,255)!important","background-color":"rgba(90, 242, 156, 0.2)","padding":"5px"}),
|
1245 |
html.Div(id="notification_wrapper", style={"margin-top":"1rem"}),
|
|
|
1246 |
], width=12)
|
1247 |
])
|
1248 |
], className="mt-5")],
|
|
|
1625 |
),
|
1626 |
html.Div(id='output-response-avid', style={"color":"rgb(156, 242, 242)","border-radius":"3px","border":"1px solid rgb(255,255,255)!important","background-color":"rgba(156, 242, 242, 0.2)","padding":"5px"}),
|
1627 |
html.Div(id="notification_wrapper-avid", style={"margin-top":"1rem"}),
|
|
|
1628 |
], width=12)
|
1629 |
])
|
1630 |
], className="mt-5")],
|
|
|
2171 |
# You could also return a 404 "URL not found" page here
|
2172 |
return view, url
|
2173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2174 |
@callback(
|
2175 |
Output("output-response", "children"),
|
2176 |
Output("notification_wrapper", "children", allow_duplicate=True),
|
2177 |
Input("num-bcc", "value"),
|
2178 |
Input("maquette-dropdown", "value"),
|
2179 |
Input("submit-button", "n_clicks"),
|
|
|
2180 |
State("url", "pathname"),
|
2181 |
running=[[Output("output-response", "children"), "", None]],
|
2182 |
prevent_initial_call=True,
|
2183 |
)
|
2184 |
+
def display_status(num, current, n_clicks, pathname):
|
2185 |
+
if not n_clicks:
|
2186 |
return no_update, []
|
2187 |
|
2188 |
if not current:
|
|
|
2195 |
current_url = current
|
2196 |
|
2197 |
print(f"Fichier Maquette sélectionné: {current_url}")
|
2198 |
+
agent = init_agent_state(current_url, num, pathname)
|
2199 |
try:
|
2200 |
df = agent[0]
|
2201 |
result = agent[1]
|
|
|
2209 |
Input("num-bcc-avid", "value"),
|
2210 |
Input("maquette-dropdown-avid", "value"),
|
2211 |
Input("submit-button-avid", "n_clicks"),
|
|
|
2212 |
State("url", "pathname"),
|
2213 |
running=[[Output("output-response-avid", "children"), "", None]],
|
2214 |
prevent_initial_call=True,
|
2215 |
)
|
2216 |
+
def display_status(num, current, n_clicks, pathname):
|
2217 |
+
if not n_clicks:
|
2218 |
return no_update, []
|
2219 |
|
2220 |
if not current:
|
|
|
2228 |
|
2229 |
print(f"Fichier Maquette sélectionné: {current_url}")
|
2230 |
|
2231 |
+
agent = init_agent_state(current_url, num, pathname)
|
2232 |
try:
|
2233 |
df = agent[0]
|
2234 |
result = agent[1]
|
|
|
2239 |
clientside_callback(
|
2240 |
"""connected => !connected""",
|
2241 |
Output("submit-button", "disabled"),
|
|
|
2242 |
)
|
2243 |
|
2244 |
clientside_callback(
|
|
|
2247 |
return notification
|
2248 |
}""",
|
2249 |
Output("notification_wrapper", "children", allow_duplicate=True),
|
|
|
2250 |
prevent_initial_call=True,
|
2251 |
)
|
2252 |
|
2253 |
clientside_callback(
|
2254 |
"""(word, text) => text + word""",
|
2255 |
Output("output-response", "children", allow_duplicate=True),
|
|
|
2256 |
State("output-response", "children"),
|
2257 |
prevent_initial_call=True,
|
2258 |
)
|
|
|
2260 |
clientside_callback(
|
2261 |
"""connected => !connected""",
|
2262 |
Output("submit-button-avid", "disabled"),
|
|
|
2263 |
)
|
2264 |
|
2265 |
clientside_callback(
|
|
|
2268 |
return notification
|
2269 |
}""",
|
2270 |
Output("notification_wrapper-avid", "children", allow_duplicate=True),
|
|
|
2271 |
prevent_initial_call=True,
|
2272 |
)
|
2273 |
|
2274 |
clientside_callback(
|
2275 |
"""(word, text) => text + word""",
|
2276 |
Output("output-response-avid", "children", allow_duplicate=True),
|
|
|
2277 |
State("output-response-avid", "children"),
|
2278 |
prevent_initial_call=True,
|
2279 |
)
|