import json from collections import OrderedDict from pathlib import Path import streamlit as st SEEKER_ICON = "https://github.com/McGill-NLP/FaithDial/raw/gh-pages/assets/img/seeker.png" EXPERT_ICON = "https://github.com/McGill-NLP/FaithDial/raw/gh-pages/assets/img/expert.png" begin_badges = { "Entailment": "success", "Hallucination": "danger", "Partial Hallucination": "warning", "Generic": "secondary", "Uncooperative": "secondary", } st.set_page_config(page_title="FaithDial Explorer", page_icon=":stars:", layout="wide") st.markdown( """ """, unsafe_allow_html=True, ) st.sidebar.write( """

FaithDial

""", unsafe_allow_html=True, ) # st.sidebar.image("datasets_logo_name.png", width=300) st.sidebar.subheader("A Faithful Benchmark for Information-Seeking Dialogue") @st.cache_data def load_dialogues(): """ Loads the samples from the data folder. """ samples_path = Path(__file__).parent / "faithdial-samples.jsonl" with samples_path.open("r") as f: samples = [json.loads(line) for line in f] topics = OrderedDict() for i, sample in enumerate(samples): if sample.get("topic", None): if sample["topic"] not in topics: key = sample["topic"] else: key = f"{sample['topic']} (dialogue {i + 1})" else: key = f"Dialogue {i + 1}" topics[key] = sample return topics dialogues = load_dialogues() topics = tuple(dialogues.keys()) st.sidebar.markdown( "FaithDial contains 50,761 turns spanning 5649 conversations. Below you can choose a topic and visualize the conversation on the right hand side. Download the data from [here](https://huggingface.co/datasets/McGill-NLP/FaithDial)." ) selected_topic = st.sidebar.radio("Pick a topic", topics, help="", key="topic_picker") st.sidebar.markdown( "
Proudly collected at McGill-NLP in collaboration with Amii & IBM
", unsafe_allow_html=True ) if selected_topic is not None: selected_dialogue = dialogues[selected_topic] st.write( f"""   {selected_topic}""", unsafe_allow_html=True) st.markdown("***") for i, exchange in enumerate(selected_dialogue["exchanges"]): turn = i + 1 # if exchange["history"]: # history_template = """ #
#
History
#
# """ # for i, history in enumerate(exchange["history"]): # icon = SEEKER_ICON if i % 2 == 0 else EXPERT_ICON # history_template += ( # f"""

{history}

""" # ) # history_template += """
""" # st.write(history_template, unsafe_allow_html=True) # st.write(f"""

Turn {turn}

""", unsafe_allow_html=True) evidence_col, exchange_col = st.columns((0.7, 1)) evidence_template = f"""
""" evidence_col.write(evidence_template, unsafe_allow_html=True) parallel_template = """
{seeker}
{expert}
""" seeker = exchange["seeker"] is_seeker_modified = bool(seeker.get("OldText", None)) expert = exchange["expert"] is_expert_modified = bool(expert.get("OldText", None)) exchange_pane = exchange_col.empty() seeker_template = f""" Seeker: {seeker["Text"]}""" expert_template = f""" Wizard: {expert["Text"]}""" exchange_pane.write( parallel_template.format( seeker=seeker_template, expert=expert_template, ), unsafe_allow_html=True, ) show_original = exchange_col.checkbox("Show original", key=f"show-{selected_topic}-{turn}") if show_original: apprentice_template = f"Apprentice: {seeker.get('OldText', None) or seeker['Text']}" badges = f"""{expert['BEGIN']} {" ".join("{}".format(v) for v in sorted(expert['VRM']))}""" wizard_template = f"""Wizard: {expert.get("OldText", None) or expert["Text"]}    {badges}""" original_template = """
{apprentice}
{wizard}
""" exchange_col.write( original_template.format(apprentice=apprentice_template, wizard=wizard_template, turn=turn), unsafe_allow_html=True, ) seeker_template = f""" Seeker: {"" if is_seeker_modified else ""}{seeker["Text"]}""" expert_template = f""" Wizard: {"" if is_expert_modified else ""}{expert["Text"]}""" exchange_pane.write( parallel_template.format( seeker=seeker_template, expert=expert_template, ), unsafe_allow_html=True, ) exchange_col.markdown('') exchange_col.markdown("""***""")