Maia Pelletier commited on
Commit
826090a
·
1 Parent(s): b5ca27a

de-dup in-line citations

Browse files
Files changed (1) hide show
  1. app.py +9 -0
app.py CHANGED
@@ -10,6 +10,7 @@ warnings.filterwarnings(
10
  category=FutureWarning,
11
  )
12
 
 
13
  import gradio as gr
14
  from gradio.themes.base import Base
15
  from gradio.themes.utils import colors, fonts, sizes
@@ -271,6 +272,14 @@ Answer:"""
271
  url = context_index_to_url.get(i)
272
  replacement = f"[{source_label}]({url})" if url else source_label
273
  response_text = response_text.replace(f"[Context {i}]", replacement)
 
 
 
 
 
 
 
 
274
  # Only append references when the model actually answered
275
  no_answer_phrase = "The provided context does not contain enough information to answer this question."
276
  no_answer_replacement = "The organic documents provided do not contain enough information to answer your question. For more information, try taking a look at the [Canadian Food Inspection Agency](https://inspection.canada.ca/en/food-labels/organic-products/) website."
 
10
  category=FutureWarning,
11
  )
12
 
13
+ import re
14
  import gradio as gr
15
  from gradio.themes.base import Base
16
  from gradio.themes.utils import colors, fonts, sizes
 
272
  url = context_index_to_url.get(i)
273
  replacement = f"[{source_label}]({url})" if url else source_label
274
  response_text = response_text.replace(f"[Context {i}]", replacement)
275
+ # Deduplicate repeated inline markdown links — keep first as link, rest as plain text
276
+ seen_inline = set()
277
+ def _dedup_link(m):
278
+ if m.group(0) in seen_inline:
279
+ return m.group(1)
280
+ seen_inline.add(m.group(0))
281
+ return m.group(0)
282
+ response_text = re.sub(r'\[([^\]]+)\]\([^)]+\)', _dedup_link, response_text)
283
  # Only append references when the model actually answered
284
  no_answer_phrase = "The provided context does not contain enough information to answer this question."
285
  no_answer_replacement = "The organic documents provided do not contain enough information to answer your question. For more information, try taking a look at the [Canadian Food Inspection Agency](https://inspection.canada.ca/en/food-labels/organic-products/) website."