Spaces:
Running
Running
File size: 3,473 Bytes
3146d66 785c044 3146d66 98a3259 6780f80 a645df8 98a3259 2b2ab5b 3146d66 a645df8 98a3259 3146d66 785c044 ec05364 3146d66 ec05364 2b2ab5b ec05364 3146d66 18b8750 ec05364 18b8750 98a3259 ec05364 18b8750 ec05364 98a3259 ec05364 785c044 ec05364 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
import asyncio
import os
from importlib import import_module
import pandas as pd
import rich
import streamlit as st
import weave
from dotenv import load_dotenv
from guardrails_genie.guardrails import GuardrailManager
from guardrails_genie.llm import OpenAIModel
from guardrails_genie.metrics import AccuracyMetric
def initialize_session_state():
load_dotenv()
if "weave_project_name" not in st.session_state:
st.session_state.weave_project_name = "guardrails-genie"
if "uploaded_file" not in st.session_state:
st.session_state.uploaded_file = None
if "dataset_name" not in st.session_state:
st.session_state.dataset_name = None
if "preview_in_app" not in st.session_state:
st.session_state.preview_in_app = False
if "is_dataset_published" not in st.session_state:
st.session_state.is_dataset_published = False
if "publish_dataset_button" not in st.session_state:
st.session_state.publish_dataset_button = False
if "dataset_ref" not in st.session_state:
st.session_state.dataset_ref = None
initialize_session_state()
st.title(":material/monitoring: Evaluation")
weave_project_name = st.sidebar.text_input(
"Weave project name", value=st.session_state.weave_project_name
)
st.session_state.weave_project_name = weave_project_name
if st.session_state.weave_project_name != "":
weave.init(project_name=st.session_state.weave_project_name)
uploaded_file = st.sidebar.file_uploader(
"Upload the evaluation dataset as a CSV file", type="csv"
)
st.session_state.uploaded_file = uploaded_file
if st.session_state.uploaded_file is not None:
dataset_name = st.sidebar.text_input("Evaluation dataset name", value=None)
st.session_state.dataset_name = dataset_name
preview_in_app = st.sidebar.toggle("Preview in app", value=False)
st.session_state.preview_in_app = preview_in_app
publish_dataset_button = st.sidebar.button("Publish dataset")
st.session_state.publish_dataset_button = publish_dataset_button
if (
st.session_state.publish_dataset_button
and (
st.session_state.dataset_name is not None
and st.session_state.dataset_name != ""
)
):
with st.expander("Evaluation Dataset Preview", expanded=True):
dataframe = pd.read_csv(st.session_state.uploaded_file)
data_list = dataframe.to_dict(orient="records")
dataset = weave.Dataset(name=st.session_state.dataset_name, rows=data_list)
st.session_state.dataset_ref = weave.publish(dataset)
entity = st.session_state.dataset_ref.entity
project = st.session_state.dataset_ref.project
dataset_name = st.session_state.dataset_name
digest = st.session_state.dataset_ref._digest
dataset_url = f"https://wandb.ai/{entity}/{project}/weave/objects/{dataset_name}/versions/{digest}"
st.markdown(
f"Dataset published to [**Weave**]({dataset_url})"
)
if preview_in_app:
st.dataframe(dataframe.head(20))
if len(dataframe) > 20:
st.markdown(
f"⚠️ Dataset is too large to preview in app, please explore in the [**Weave UI**]({dataset_url})"
)
st.session_state.is_dataset_published = True
if st.session_state.is_dataset_published:
st.write("Maza Ayega")
|