Spaces:
Paused
Paused
Carlos Rosas
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -26,7 +26,6 @@ model = AutoModelForCausalLM.from_pretrained(model_name, token=hf_token)
|
|
26 |
model.to(device)
|
27 |
|
28 |
# Set tokenizer configuration
|
29 |
-
|
30 |
tokenizer.eos_token = "<|answer_end|>"
|
31 |
eos_token_id=tokenizer.eos_token_id
|
32 |
tokenizer.pad_token = tokenizer.eos_token
|
@@ -98,20 +97,21 @@ class pleiasBot:
|
|
98 |
analysis = parts[0].strip()
|
99 |
answer = parts[1].replace("<|answer_start|>", "").replace("<|answer_end|>", "").strip()
|
100 |
|
101 |
-
# Format
|
102 |
-
|
|
|
103 |
else:
|
104 |
-
|
|
|
105 |
|
106 |
-
generated_text = '<h2 style="text-align:center">RΓ©ponse</h3>\n<div class="generation">' + format_references(formatted_text) + "</div>"
|
107 |
fiches_html = '<h2 style="text-align:center">Sources</h3>\n' + fiches_html
|
108 |
-
return
|
109 |
|
110 |
except Exception as e:
|
111 |
print(f"Error during generation: {str(e)}")
|
112 |
import traceback
|
113 |
traceback.print_exc()
|
114 |
-
return None, None
|
115 |
|
116 |
def format_references(text):
|
117 |
ref_pattern = r'<ref name="([^"]+)">"([^"]+)"</ref>'
|
@@ -207,32 +207,43 @@ css = """
|
|
207 |
|
208 |
# Gradio interface
|
209 |
def gradio_interface(user_message):
|
210 |
-
response, sources = pleias_bot.predict(user_message)
|
211 |
-
return response, sources
|
212 |
|
213 |
# Create Gradio app
|
214 |
demo = gr.Blocks(css=css)
|
215 |
|
216 |
with demo:
|
|
|
217 |
gr.HTML("""
|
218 |
-
<div style="display: flex; justify-content: center; width: 100%; background-color: black; padding:
|
219 |
<pre style="font-family: monospace; line-height: 1.2; font-size: 24px; color: #00ffea; margin: 0;">
|
220 |
βββββββββββββββββββββ
|
221 |
-
β
|
222 |
βββββββββββββββββββββ
|
223 |
</pre>
|
224 |
</div>
|
225 |
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
with gr.Row():
|
227 |
with gr.Column(scale=2):
|
228 |
-
|
229 |
-
text_button = gr.Button("Interroger pleias-RAG")
|
230 |
with gr.Column(scale=3):
|
231 |
-
|
|
|
|
|
232 |
with gr.Row():
|
233 |
embedding_output = gr.HTML(label="Les sources utilisΓ©es")
|
234 |
|
235 |
-
text_button.click(gradio_interface,
|
|
|
|
|
236 |
|
237 |
# Launch the app
|
238 |
if __name__ == "__main__":
|
|
|
26 |
model.to(device)
|
27 |
|
28 |
# Set tokenizer configuration
|
|
|
29 |
tokenizer.eos_token = "<|answer_end|>"
|
30 |
eos_token_id=tokenizer.eos_token_id
|
31 |
tokenizer.pad_token = tokenizer.eos_token
|
|
|
97 |
analysis = parts[0].strip()
|
98 |
answer = parts[1].replace("<|answer_start|>", "").replace("<|answer_end|>", "").strip()
|
99 |
|
100 |
+
# Format each section separately
|
101 |
+
analysis_text = f'<div class="generation">' + format_references(analysis) + "</div>"
|
102 |
+
answer_text = '<h2 style="text-align:center">RΓ©ponse</h3>\n<div class="generation">' + format_references(answer) + "</div>"
|
103 |
else:
|
104 |
+
analysis_text = ""
|
105 |
+
answer_text = format_references(generated_text)
|
106 |
|
|
|
107 |
fiches_html = '<h2 style="text-align:center">Sources</h3>\n' + fiches_html
|
108 |
+
return analysis_text, answer_text, fiches_html
|
109 |
|
110 |
except Exception as e:
|
111 |
print(f"Error during generation: {str(e)}")
|
112 |
import traceback
|
113 |
traceback.print_exc()
|
114 |
+
return None, None, None
|
115 |
|
116 |
def format_references(text):
|
117 |
ref_pattern = r'<ref name="([^"]+)">"([^"]+)"</ref>'
|
|
|
207 |
|
208 |
# Gradio interface
|
209 |
def gradio_interface(user_message):
|
210 |
+
analysis, response, sources = pleias_bot.predict(user_message)
|
211 |
+
return analysis, response, sources
|
212 |
|
213 |
# Create Gradio app
|
214 |
demo = gr.Blocks(css=css)
|
215 |
|
216 |
with demo:
|
217 |
+
# Header with black bar
|
218 |
gr.HTML("""
|
219 |
+
<div style="display: flex; justify-content: center; width: 100%; background-color: black; padding: 7px 0;">
|
220 |
<pre style="font-family: monospace; line-height: 1.2; font-size: 24px; color: #00ffea; margin: 0;">
|
221 |
βββββββββββββββββββββ
|
222 |
+
β pleias-RAG 1.0 β
|
223 |
βββββββββββββββββββββ
|
224 |
</pre>
|
225 |
</div>
|
226 |
""")
|
227 |
+
|
228 |
+
# Input section
|
229 |
+
with gr.Column(scale=2):
|
230 |
+
text_input = gr.Textbox(label="Votre question ou votre instruction", lines=3)
|
231 |
+
text_button = gr.Button("Interroger pleias-RAG")
|
232 |
+
|
233 |
+
# Two columns for output: Analysis and Response
|
234 |
with gr.Row():
|
235 |
with gr.Column(scale=2):
|
236 |
+
text_output = gr.HTML(label="Analyse des sources")
|
|
|
237 |
with gr.Column(scale=3):
|
238 |
+
response_output = gr.HTML(label="RΓ©ponse")
|
239 |
+
|
240 |
+
# Sources at the bottom
|
241 |
with gr.Row():
|
242 |
embedding_output = gr.HTML(label="Les sources utilisΓ©es")
|
243 |
|
244 |
+
text_button.click(gradio_interface,
|
245 |
+
inputs=text_input,
|
246 |
+
outputs=[text_output, response_output, embedding_output])
|
247 |
|
248 |
# Launch the app
|
249 |
if __name__ == "__main__":
|