Spaces:
Paused
Paused
Carlos Rosas
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -63,7 +63,7 @@ def hybrid_search(text):
|
|
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 |
|
69 |
def predict(self, user_message):
|
@@ -71,6 +71,7 @@ class pleiasBot:
|
|
71 |
|
72 |
detailed_prompt = f"""<|query_start|>{user_message}<|query_end|>\n{fiches}\n<|source_analysis_start|>"""
|
73 |
|
|
|
74 |
input_ids = tokenizer.encode(detailed_prompt, return_tensors="pt").to(device)
|
75 |
attention_mask = torch.ones_like(input_ids)
|
76 |
|
@@ -97,8 +98,8 @@ class pleiasBot:
|
|
97 |
analysis = parts[0].strip()
|
98 |
answer = parts[1].replace("<|answer_start|>", "").replace("<|answer_end|>", "").strip()
|
99 |
|
100 |
-
# Format with section titles
|
101 |
-
formatted_text = f'<div class="section-title">Sources Analysis</div>\n\n{analysis}\n\n<div class="section-title">Answer</div>\n\n{answer}'
|
102 |
else:
|
103 |
formatted_text = generated_text
|
104 |
|
@@ -172,28 +173,20 @@ css = """
|
|
172 |
border-radius: 6px;
|
173 |
border: 1px solid #e5e7eb;
|
174 |
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
175 |
-
|
176 |
-
/* Position the tooltip */
|
177 |
position: absolute;
|
178 |
z-index: 1;
|
179 |
bottom: 125%;
|
180 |
left: 50%;
|
181 |
transform: translateX(-50%);
|
182 |
-
|
183 |
-
/* Size and formatting */
|
184 |
min-width: 300px;
|
185 |
max-width: 400px;
|
186 |
white-space: normal;
|
187 |
font-size: 0.9em;
|
188 |
line-height: 1.4;
|
189 |
}
|
190 |
-
|
191 |
-
/* Show tooltip on hover */
|
192 |
.tooltip:hover .tooltiptext {
|
193 |
visibility: visible;
|
194 |
}
|
195 |
-
|
196 |
-
/* Add arrow to tooltip */
|
197 |
.tooltip .tooltiptext::after {
|
198 |
content: "";
|
199 |
position: absolute;
|
@@ -204,7 +197,14 @@ css = """
|
|
204 |
border-style: solid;
|
205 |
border-color: #fff transparent transparent transparent;
|
206 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
"""
|
|
|
208 |
# Gradio interface
|
209 |
def gradio_interface(user_message):
|
210 |
response, sources = pleias_bot.predict(user_message)
|
|
|
63 |
return document, document_html
|
64 |
|
65 |
class pleiasBot:
|
66 |
+
def __init__(self, system_prompt="Tu es Appli, un asistant de recherche qui donne des responses sourcées"):
|
67 |
self.system_prompt = system_prompt
|
68 |
|
69 |
def predict(self, user_message):
|
|
|
71 |
|
72 |
detailed_prompt = f"""<|query_start|>{user_message}<|query_end|>\n{fiches}\n<|source_analysis_start|>"""
|
73 |
|
74 |
+
# Convert inputs to tensor
|
75 |
input_ids = tokenizer.encode(detailed_prompt, return_tensors="pt").to(device)
|
76 |
attention_mask = torch.ones_like(input_ids)
|
77 |
|
|
|
98 |
analysis = parts[0].strip()
|
99 |
answer = parts[1].replace("<|answer_start|>", "").replace("<|answer_end|>", "").strip()
|
100 |
|
101 |
+
# Format with section titles using strong tags for extra emphasis
|
102 |
+
formatted_text = f'<div class="section-title"><strong>Sources Analysis</strong></div>\n\n{analysis}\n\n<div class="section-title"><strong>Answer</strong></div>\n\n{answer}'
|
103 |
else:
|
104 |
formatted_text = generated_text
|
105 |
|
|
|
173 |
border-radius: 6px;
|
174 |
border: 1px solid #e5e7eb;
|
175 |
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
|
|
|
|
176 |
position: absolute;
|
177 |
z-index: 1;
|
178 |
bottom: 125%;
|
179 |
left: 50%;
|
180 |
transform: translateX(-50%);
|
|
|
|
|
181 |
min-width: 300px;
|
182 |
max-width: 400px;
|
183 |
white-space: normal;
|
184 |
font-size: 0.9em;
|
185 |
line-height: 1.4;
|
186 |
}
|
|
|
|
|
187 |
.tooltip:hover .tooltiptext {
|
188 |
visibility: visible;
|
189 |
}
|
|
|
|
|
190 |
.tooltip .tooltiptext::after {
|
191 |
content: "";
|
192 |
position: absolute;
|
|
|
197 |
border-style: solid;
|
198 |
border-color: #fff transparent transparent transparent;
|
199 |
}
|
200 |
+
.section-title {
|
201 |
+
font-weight: bold;
|
202 |
+
font-size: 12px;
|
203 |
+
margin-bottom: 1em;
|
204 |
+
margin-top: 1em;
|
205 |
+
}
|
206 |
"""
|
207 |
+
|
208 |
# Gradio interface
|
209 |
def gradio_interface(user_message):
|
210 |
response, sources = pleias_bot.predict(user_message)
|