Carlos Rosas commited on
Commit
8184f41
Β·
verified Β·
1 Parent(s): 381f8ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -15
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 with section titles using strong tags for extra emphasis
102
- formatted_text = f'<div class="section-title"><strong>Analyse des sources</strong></div>\n\n{analysis}\n\n<div class="section-title"><strong>RΓ©ponse</strong></div>\n\n{answer}'
 
103
  else:
104
- formatted_text = generated_text
 
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 generated_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
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: 10px 0;">
219
  <pre style="font-family: monospace; line-height: 1.2; font-size: 24px; color: #00ffea; margin: 0;">
220
  ╔═══════════════════╗
221
- β•‘ pleias-RAG 1.0 β•‘
222
  β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
223
  </pre>
224
  </div>
225
  """)
 
 
 
 
 
 
 
226
  with gr.Row():
227
  with gr.Column(scale=2):
228
- text_input = gr.Textbox(label="Votre question ou votre instruction", lines=3)
229
- text_button = gr.Button("Interroger pleias-RAG")
230
  with gr.Column(scale=3):
231
- text_output = gr.HTML(label="La réponse du modèle")
 
 
232
  with gr.Row():
233
  embedding_output = gr.HTML(label="Les sources utilisΓ©es")
234
 
235
- text_button.click(gradio_interface, inputs=text_input, outputs=[text_output, embedding_output])
 
 
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__":