Refactor language options and enhance table description display in chatbot UI

This commit is contained in:
sepehr 2025-03-09 09:08:09 +01:00
parent 9d142c269d
commit 0a9e2d4567
2 changed files with 97 additions and 66 deletions

File diff suppressed because one or more lines are too long

View File

@ -53,8 +53,7 @@ LANGUAGE_MAPPING = {
"Italiano": "italiano",
"中文": "Chinese",
"日本語": "Japanese",
"العربية": "Arabic",
"فارسی": "Persian" # Added Persian language
"العربية": "Arabic"
}
# Initialiser le chatbot RAG avec le modèle par défaut
@ -389,11 +388,12 @@ def display_tables():
print(f"Error formatting table {idx}: {e}")
table_html = f'<pre>{table_data}</pre>'
# Create the table container with metadata - REMOVED description
# Create the table container with metadata
html += f"""
<div style="margin-bottom: 20px; border: 1px solid #ddd; padding: 15px; border-radius: 8px;">
<h3>{table['caption']}</h3>
<p style="color:#666; font-size:0.9em;">Source: {table['source']}, Page: {table['page']}</p>
<p><strong>Description:</strong> {table['description']}</p>
{table_html}
</div>
"""
@ -448,7 +448,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
# Sélecteur de langue
language_selector = gr.Dropdown(
choices=["Français", "English", "Español", "Deutsch", "Italiano", "中文", "日本語", "العربية", "فارسی"],
choices=["Français", "English", "Español", "Deutsch", "Italiano", "中文", "日本語", "العربية"],
value="Français",
label="Langue des réponses",
info="Choisir la langue dans laquelle l'assistant répondra"
@ -535,7 +535,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
/* Improved styles for equations */
.katex { font-size: 1.1em !important; }
.math-inline { background: #f8f9fa; padding: 2px 5px; border-radius: 4px; }
.math-display { background: #f8f9fa; margin: 10px 0; padding: 10px; border-radius: 5px; overflow-x: auto; text-align: center; }
.math-display { background: #f8f9f9; margin: 10px 0; padding: 10px; border-radius: 5px; overflow-x: auto; text-align: center; }
/* Table styles */
table {
@ -578,15 +578,15 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
delimiters: [
{left: '$$', right: '$$', display: true},
{left: '$', right: '$', display: false},
{left: '\\\\(', right: '\\\\)', display: false},
{left: '\\\\[', right: '\\\\]', display: true}
{left: '\\(', right: '\\)', display: false},
{left: '\\[', right: '\\]', display: true}
],
throwOnError: false,
trust: true,
strict: false,
macros: {
"\\\\R": "\\\\mathbb{R}",
"\\\\N": "\\\\mathbb{N}"
"\\R": "\\mathbb{R}",
"\\N": "\\mathbb{N}"
}
});
} catch (e) {
@ -617,12 +617,12 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
function prepareLatexInText(text) {
// Make sure dollar signs used for math have proper spacing
// First, protect existing well-formed math expressions
text = text.replace(/(\\$\\$[^\\$]+\\$\\$)/g, '<protect>$1</protect>'); // protect display math
text = text.replace(/(\\$[^\\$\\n]+\\$)/g, '<protect>$1</protect>'); // protect inline math
text = text.replace(/(\$\$[^\$]+\$\$)/g, '<protect>$1</protect>'); // protect display math
text = text.replace(/(\$[^\$\n]+\$)/g, '<protect>$1</protect>'); // protect inline math
// Fix common LaTeX formatting issues outside protected regions
text = text.replace(/([^<]protect[^>]*)(\\$)([^\\s])/g, '$1$2 $3'); // Add space after $ if needed
text = text.replace(/([^\\s])(\\$)([^<]protect[^>]*)/g, '$1 $2$3'); // Add space before $ if needed
text = text.replace(/([^<]protect[^>]*)(\$)([^\s])/g, '$1$2 $3'); // Add space after $ if needed
text = text.replace(/([^\s])(\$)([^<]protect[^>]*)/g, '$1 $2$3'); // Add space before $ if needed
// Handle subscripts: transform x_1 into x_{1} for better LaTeX compatibility
text = text.replace(/([a-zA-Z])_([0-9a-zA-Z])/g, '$1_{$2}');