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