Team Ai
Apppublic

Rubywong123/UI_Human-Study

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes
app.py104 linesDownload Raw Back to root
1import streamlit as st2import pickle3import os4import pandas as pd5from datetime import datetime6 7 8root = "human_study"9# Simulated data structure10data_path = {11    "RAG-based web simulation": 'train_set_web_rag',12    "RAG-free web simulation": 'train_set_web_rag_free',13    'RAG-based android simulation': 'train_set_android_rag',14    'RAG-free android simulation': 'train_set_android_rag_free',15    "Ablation web simulation": 'ablation_simulation',16    "Real web trajectories": 'train_set_web_real',17}18 19st.set_page_config(layout="wide")20 21# Top bar for trajectory selection22with st.container():23    st.title("Trajectory Human Evaluation")24 25    top_col1, top_col2 = st.columns(2)26    with top_col1:27        class_choice = st.selectbox("Select Class", list(data_path.keys()))28    with top_col2:29        traj_index = st.number_input("Trajectory Index (0-149)", min_value=0, max_value=149, step=1)30 31# Load the trajectory32traj_path = os.path.join(root, data_path[class_choice], f"traj_{traj_index}")33with open(os.path.join(traj_path, "trajectory.pkl"), "rb") as f:34    traj = pickle.load(f)35 36with open(os.path.join(traj_path, "instruction.txt"), "r") as f:37    instruction = f.read()38max_step = len(traj) - 139 40# Layout for main content41left_col, right_col = st.columns([6, 4])42 43# Trajectory display44with left_col:45    st.header("Trajectory Viewer")46    st.write(f"**Class:** {class_choice} | **Trajectory #{traj_index}**")47    st.write(f"**Instruction:** {instruction}")48    step_index = st.slider("Select Step", 0, max_step, 0, key="step_slider")49    st.write(f"**Step {step_index + 1}/{max_step + 1}:**")50    history = '\n'.join(traj[step_index][4])51    if not history:52        history = "None"53    st.text_area("**Action History**", history, height = 100)54 55    if 'android' in class_choice.lower():56        # use indexed state57        state = traj[step_index][0]58        indexed_state = "\n".join([f"Element {i}: {s}" for i, s in enumerate(state.split('\n')) if s.strip()])59        st.text_area("**Current State:**", indexed_state, height=200)60    else:61        st.text_area("**Current State:**", traj[step_index][0], height=200)62    st.write(f"**Thoughts:** {traj[step_index][1]}")63    st.write(f"**Actions:** {traj[step_index][2]}")64    st.write(f"**Step Summarization:** {traj[step_index][3]}")65 66with right_col:67    st.header("Evaluation Form")68 69    realistic = st.radio("1. Is the task realistic?", ["Yes", "No"])70    state_reasonable = st.radio("2. Is the state reasonable?", ["Yes", "No"])71    actions_valid = st.radio("3. Do actions make sense?", ["Yes", "No"])72    thoughts_valid = st.radio("4. Do thoughts make sense (logic)?", ["Yes", "No"])73    task_completed = st.radio("5. Is the task completed?", ["Yes", "No"])74    consistent = st.radio("6. Is the trajectory consistent?", ["Yes", "No"])75    irrelevant_step_count = st.number_input(76    "7. Number of irrelevant (waste) steps", min_value=0, max_value=max_step + 1, step=1, key="irrelevant_steps"77        )78    abstract_topic = st.radio("8. Is the topic abstracted?", ["Yes", "No"])79 80    if st.button("Submit Evaluation"):81        record = {82            "timestamp": datetime.now().isoformat(),83            "class": class_choice,84            "trajectory_index": traj_index,85            "step_index": step_index,86            "realistic": realistic,87            "state_reasonable": state_reasonable,88            "actions_valid": actions_valid,89            "thoughts_valid": thoughts_valid,90            "task_completed": task_completed,91            "consistent": consistent,92            "irrelevant_steps": irrelevant_step_count,93            "abstract_topic": abstract_topic94        }95 96        df = pd.DataFrame([record])97        if not os.path.exists("evaluations.csv"):98            df.to_csv("evaluations.csv", index=False)99        else:100            df.to_csv("evaluations.csv", mode='a', header=False, index=False)101 102        st.success("Submission recorded!")103 104