Spaces:
Paused
Paused
Carlos Rosas
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -62,7 +62,7 @@ def hybrid_search(text):
|
|
62 |
document_html = '<div id="source_listing">' + "".join(document_html) + "</div>"
|
63 |
return document, document_html
|
64 |
|
65 |
-
class
|
66 |
def __init__(self, system_prompt="Tu es un asistant de recherche qui donne des responses sourcées"):
|
67 |
self.system_prompt = system_prompt
|
68 |
|
@@ -102,83 +102,98 @@ class CassandreChatBot:
|
|
102 |
return None, None
|
103 |
|
104 |
def format_references(text):
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
parts = []
|
109 |
current_pos = 0
|
110 |
ref_number = 1
|
111 |
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
ref_text = text[start_pos + len(ref_start_marker):end_pos].replace('\n', ' ').strip()
|
125 |
-
ref_text_encoded = ref_text.replace("&", "&").replace("<", "<").replace(">", ">")
|
126 |
-
|
127 |
-
ref_end_pos = text.find(ref_end_marker, end_pos)
|
128 |
-
if ref_end_pos == -1:
|
129 |
-
break
|
130 |
-
|
131 |
-
ref_id = text[end_pos + 2:ref_end_pos].strip()
|
132 |
-
|
133 |
-
tooltip_html = f'<span class="tooltip" data-refid="{ref_id}" data-text="{ref_id}: {ref_text_encoded}"><a href="#{ref_id}">[{ref_number}]</a></span>'
|
134 |
parts.append(tooltip_html)
|
135 |
-
|
136 |
-
current_pos =
|
137 |
-
ref_number
|
138 |
-
|
|
|
|
|
|
|
139 |
return ''.join(parts)
|
140 |
|
141 |
-
# Initialize the
|
142 |
-
cassandre_bot =
|
143 |
|
144 |
# CSS for styling
|
145 |
css = """
|
146 |
.generation {
|
147 |
-
margin-left:2em;
|
148 |
-
margin-right:2em;
|
149 |
}
|
150 |
:target {
|
151 |
background-color: #CCF3DF;
|
152 |
-
|
153 |
.source {
|
154 |
-
float:left;
|
155 |
-
max-width:17%;
|
156 |
-
margin-left:2%;
|
157 |
}
|
158 |
.tooltip {
|
159 |
position: relative;
|
|
|
|
|
160 |
cursor: pointer;
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
position: absolute;
|
168 |
-
left: 0;
|
169 |
-
top: 120%;
|
170 |
-
white-space: pre-wrap;
|
171 |
-
width: 500px;
|
172 |
-
max-width: 500px;
|
173 |
z-index: 1;
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
"""
|
183 |
|
184 |
# Gradio interface
|
|
|
62 |
document_html = '<div id="source_listing">' + "".join(document_html) + "</div>"
|
63 |
return document, document_html
|
64 |
|
65 |
+
class pleiasBot:
|
66 |
def __init__(self, system_prompt="Tu es un asistant de recherche qui donne des responses sourcées"):
|
67 |
self.system_prompt = system_prompt
|
68 |
|
|
|
102 |
return None, None
|
103 |
|
104 |
def format_references(text):
|
105 |
+
# New ref format pattern
|
106 |
+
ref_pattern = r'<ref name="([^"]+)">"([^"]+)"</ref>'
|
107 |
+
|
108 |
parts = []
|
109 |
current_pos = 0
|
110 |
ref_number = 1
|
111 |
|
112 |
+
import re
|
113 |
+
for match in re.finditer(ref_pattern, text):
|
114 |
+
# Add text before the reference
|
115 |
+
parts.append(text[current_pos:match.start()])
|
116 |
+
|
117 |
+
# Extract reference components
|
118 |
+
ref_id = match.group(1) # The source ID
|
119 |
+
ref_text = match.group(2).strip() # The reference text
|
120 |
+
|
121 |
+
# Create tooltip HTML
|
122 |
+
tooltip_html = f'<span class="tooltip"><strong>[{ref_number}]</strong><span class="tooltiptext"><strong>{ref_number}:</strong> {ref_text}</span></span>'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
parts.append(tooltip_html)
|
124 |
+
|
125 |
+
current_pos = match.end()
|
126 |
+
ref_number += 1
|
127 |
+
|
128 |
+
# Add any remaining text
|
129 |
+
parts.append(text[current_pos:])
|
130 |
+
|
131 |
return ''.join(parts)
|
132 |
|
133 |
+
# Initialize the pleiasBot
|
134 |
+
cassandre_bot = pleiasBot()
|
135 |
|
136 |
# CSS for styling
|
137 |
css = """
|
138 |
.generation {
|
139 |
+
margin-left: 2em;
|
140 |
+
margin-right: 2em;
|
141 |
}
|
142 |
:target {
|
143 |
background-color: #CCF3DF;
|
144 |
+
}
|
145 |
.source {
|
146 |
+
float: left;
|
147 |
+
max-width: 17%;
|
148 |
+
margin-left: 2%;
|
149 |
}
|
150 |
.tooltip {
|
151 |
position: relative;
|
152 |
+
display: inline-block;
|
153 |
+
color: #2563eb;
|
154 |
cursor: pointer;
|
155 |
+
}
|
156 |
+
.tooltip .tooltiptext {
|
157 |
+
visibility: hidden;
|
158 |
+
background-color: #fff;
|
159 |
+
color: #000;
|
160 |
+
text-align: left;
|
161 |
+
padding: 12px;
|
162 |
+
border-radius: 6px;
|
163 |
+
border: 1px solid #e5e7eb;
|
164 |
+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
165 |
+
|
166 |
+
/* Position the tooltip */
|
167 |
position: absolute;
|
|
|
|
|
|
|
|
|
|
|
168 |
z-index: 1;
|
169 |
+
bottom: 125%;
|
170 |
+
left: 50%;
|
171 |
+
transform: translateX(-50%);
|
172 |
+
|
173 |
+
/* Size and formatting */
|
174 |
+
min-width: 300px;
|
175 |
+
max-width: 400px;
|
176 |
+
white-space: normal;
|
177 |
+
font-size: 0.9em;
|
178 |
+
line-height: 1.4;
|
179 |
+
}
|
180 |
+
|
181 |
+
/* Show tooltip on hover */
|
182 |
+
.tooltip:hover .tooltiptext {
|
183 |
+
visibility: visible;
|
184 |
+
}
|
185 |
+
|
186 |
+
/* Add arrow to tooltip */
|
187 |
+
.tooltip .tooltiptext::after {
|
188 |
+
content: "";
|
189 |
+
position: absolute;
|
190 |
+
top: 100%;
|
191 |
+
left: 50%;
|
192 |
+
margin-left: -5px;
|
193 |
+
border-width: 5px;
|
194 |
+
border-style: solid;
|
195 |
+
border-color: #fff transparent transparent transparent;
|
196 |
+
}
|
197 |
"""
|
198 |
|
199 |
# Gradio interface
|