Gouzi Mohaled commited on
Commit
1b56d06
·
1 Parent(s): 00f738d

modification du fichier admin_pahe.py, adapatation de la logique d'extraction de l'url du chatbt selon qu'on est dans un contexte de développement ou de production

Browse files
Files changed (1) hide show
  1. admin_page.py +31 -25
admin_page.py CHANGED
@@ -8,6 +8,7 @@ import json
8
  import asyncio
9
  import os
10
  from dotenv import load_dotenv
 
11
  from utils.admin import (
12
  get_all_users,
13
  toggle_user_status,
@@ -547,11 +548,11 @@ async def render_admin_dashboard():
547
  "Sélectionner l'assistant",
548
  options=['SANTE', 'CAR', 'BTP', 'RH', 'PILOTAGE'],
549
  format_func=lambda x: {
550
- 'SANTE': 'Colibri Vitalité ',
551
- 'CAR': 'Colibri Carburant ',
552
- 'BTP': 'Colibri Batisseur ',
553
- 'RH': 'Colibri Equipage ',
554
- 'PILOTAGE': 'Colibri Tatillon '
555
  }[x],
556
  key="chatbot_assistant_select"
557
  )
@@ -565,19 +566,22 @@ async def render_admin_dashboard():
565
  'PILOTAGE': 'Colibri Tatillon'
566
  }
567
  chatbot_title = assistant_titles.get(assistant_type, 'Flowise Bot')
568
-
569
  # Récupérer l'URL complète de l'API depuis la variable d'environnement
570
  api_url_var = f"FLOWISE_API_URL_{assistant_type}"
571
  api_url = os.getenv(api_url_var)
572
  if not api_url:
573
  st.error(f"URL de l'API non trouvée pour l'assistant {assistant_type}")
574
- return
575
-
576
- # Extraction de l'URL de base et du chatflowid
577
- apiHost = '/'.join(api_url.split('/')[:3]) # Supprimer /prediction/ID
578
- # Remplacer "flowise" par "localhost" dans apiHost
579
- apiHost = apiHost.replace("flowise", "localhost")
580
- chatflowid = api_url.split('/')[-1] # Récupérer l'ID
 
 
 
 
581
 
582
  # Configuration du chatbot en HTML
583
  st.components.v1.html(f'''
@@ -731,13 +735,18 @@ async def render_admin_dashboard():
731
  api_url = os.getenv(api_url_var)
732
  if not api_url:
733
  st.error(f"URL de l'API non trouvée pour l'assistant {assistant_type}")
734
- return
735
- # Extraction de l'URL de base et du chatflowid
736
- apiHost = '/'.join(api_url.split('/')[:3]) # Supprimer /prediction/ID
737
- # Remplacer "flowise" par "localhost" dans apiHost
738
- apiHost = apiHost.replace("flowise", "localhost")
739
- chatflowid = api_url.split('/')[-1] # Récupérer l'ID
740
-
 
 
 
 
 
741
  # Configuration du chatbot en HTML
742
  st.components.v1.html(f'''
743
  <flowise-fullchatbot></flowise-fullchatbot>
@@ -805,8 +814,8 @@ async def render_admin_dashboard():
805
  <script type="module">
806
  import Chatbot from "https://cdn.jsdelivr.net/npm/flowise-embed/dist/web.js";
807
  Chatbot.initFull({
808
- chatflowid: "c7772c60-e798-4d02-809f-654170560e91",
809
- apiHost: "http://localhost:3000",
810
  theme: {
811
  chatWindow: {
812
  showTitle: true,
@@ -861,9 +870,6 @@ async def render_admin_dashboard():
861
  ''', height=800)
862
 
863
 
864
-
865
-
866
-
867
 
868
 
869
 
 
8
  import asyncio
9
  import os
10
  from dotenv import load_dotenv
11
+ from urllib.parse import urlparse
12
  from utils.admin import (
13
  get_all_users,
14
  toggle_user_status,
 
548
  "Sélectionner l'assistant",
549
  options=['SANTE', 'CAR', 'BTP', 'RH', 'PILOTAGE'],
550
  format_func=lambda x: {
551
+ 'SANTE': 'Colibri Vitalité ❣️',
552
+ 'CAR': 'Colibri Carburant 🚘',
553
+ 'BTP': 'Colibri Batisseur 🏠',
554
+ 'RH': 'Colibri Equipage 🪪',
555
+ 'PILOTAGE': 'Colibri Tatillon 👨🏻‍✈️'
556
  }[x],
557
  key="chatbot_assistant_select"
558
  )
 
566
  'PILOTAGE': 'Colibri Tatillon'
567
  }
568
  chatbot_title = assistant_titles.get(assistant_type, 'Flowise Bot')
 
569
  # Récupérer l'URL complète de l'API depuis la variable d'environnement
570
  api_url_var = f"FLOWISE_API_URL_{assistant_type}"
571
  api_url = os.getenv(api_url_var)
572
  if not api_url:
573
  st.error(f"URL de l'API non trouvée pour l'assistant {assistant_type}")
574
+ return None
575
+ url_parts = urlparse(api_url)
576
+ base_url = f"{url_parts.scheme}://{url_parts.netloc}"
577
+ chatflowid = url_parts.path.split('/')[-1]
578
+ # Détermination du contexte et de l'apiHost
579
+ if base_url.startswith("http://"):
580
+ # Contexte développement
581
+ apiHost = "http://localhost:3000"
582
+ else:
583
+ # Contexte production
584
+ apiHost = base_url
585
 
586
  # Configuration du chatbot en HTML
587
  st.components.v1.html(f'''
 
735
  api_url = os.getenv(api_url_var)
736
  if not api_url:
737
  st.error(f"URL de l'API non trouvée pour l'assistant {assistant_type}")
738
+ return None
739
+ url_parts = urlparse(api_url)
740
+ base_url = f"{url_parts.scheme}://{url_parts.netloc}"
741
+ chatflowid = url_parts.path.split('/')[-1]
742
+ # Détermination du contexte et de l'apiHost
743
+ if base_url.startswith("http://"):
744
+ # Contexte développement
745
+ apiHost = "http://localhost:3000"
746
+ else:
747
+ # Contexte production
748
+ apiHost = base_url
749
+
750
  # Configuration du chatbot en HTML
751
  st.components.v1.html(f'''
752
  <flowise-fullchatbot></flowise-fullchatbot>
 
814
  <script type="module">
815
  import Chatbot from "https://cdn.jsdelivr.net/npm/flowise-embed/dist/web.js";
816
  Chatbot.initFull({
817
+ chatflowid: "b624c96f-cb22-4112-bdb2-51ea8d0bac09",
818
+ apiHost: "https://reztilop-flowise-colibri.hf.space",
819
  theme: {
820
  chatWindow: {
821
  showTitle: true,
 
870
  ''', height=800)
871
 
872
 
 
 
 
873
 
874
 
875