Chat_bot_Rag/app.py

70 lines
3.3 KiB
Python

# filepath: f:\Dev\Rag\chat_bot_rag\app.py
import gradio as gr
from config.settings import DEFAULT_MODEL, QDRANT_COLLECTION_NAME, AVAILABLE_MODELS
from services.rag_service import initialize_rag_bot
from components.chatbot import process_query, reset_conversation, change_model, change_collection
from components.ui import build_interface, update_ui_language_elements
from translations.lang_mappings import UI_TRANSLATIONS, UI_SUPPORTED_LANGUAGES, LANGUAGE_MAPPING
def update_ui_language(language):
"""Fonction pour mettre à jour la langue de l'interface utilisateur"""
if language not in UI_SUPPORTED_LANGUAGES:
language = "Français" # Langue par défaut
# Récupérer les traductions pour la langue sélectionnée
translations = UI_TRANSLATIONS[language]
# Afficher un message de débogage
print(f"Mise à jour de la langue UI : {language}")
print(f"AVAILABLE_MODELS : {AVAILABLE_MODELS}")
# Retourner les valeurs mises à jour pour tous les éléments de l'interface
return [
f"# {translations['title']}", # Titre
gr.update(placeholder=translations["placeholder"]), # Placeholder du message
gr.update(value=translations["send_btn"]), # Texte du bouton d'envoi
gr.update(value=translations["clear_btn"]), # Texte du bouton d'effacement
gr.update(label=translations["ui_language_label"], info=translations["ui_language_info"]), # Label sélecteur langue UI
# IMPORTANT : Conserver les choices=AVAILABLE_MODELS ici
gr.update(label=translations["model_selector"], info=translations["model_info"], choices=AVAILABLE_MODELS),
f"{translations['model_current']}: **{DEFAULT_MODEL}**", # Statut du modèle
gr.update(label=translations["language_selector"], info=translations["language_info"], choices=list(LANGUAGE_MAPPING.keys())), # Langue réponses
gr.update(label=translations["collection_input"], info=translations["collection_info"]), # Label du champ de collection
f"{translations['collection_current']}: **{QDRANT_COLLECTION_NAME}**", # Statut de la collection
gr.update(value=translations["apply_btn"]), # Texte du bouton d'application
gr.update(label=translations["streaming_label"], info=translations["streaming_info"]), # Label du mode streaming
gr.update(label=translations["sources_label"]), # Label de l'affichage des sources
gr.update(label=translations["max_images_label"]), # Label du nombre max d'images
f"### {translations['images_title']}", # Titre des images
f"### {translations['tables_title']}" # Titre des tableaux
]
def main():
"""Main entry point for the chatbot application"""
# Initialize the RAG chatbot
initialize_rag_bot()
# Dans app.py, corriger l'appel à build_interface
interface = build_interface(
process_query_fn=process_query,
reset_conversation_fn=reset_conversation,
change_model_fn=change_model,
change_collection_fn=change_collection,
update_ui_language_fn=update_ui_language # Utiliser update_ui_language, pas update_ui_language_elements
)
# Lancer l'appli Gradio
interface.launch(
share=False,
inbrowser=True,
server_name="localhost",
server_port=7860
)
if __name__ == "__main__":
main()