Spaces:
Sleeping
Sleeping
Ashmi Banerjee
commited on
Commit
·
82a36a6
1
Parent(s):
3cce446
trial
Browse files- app.py +3 -22
- utils/loaders.py +25 -0
- views/nav_buttons.py +1 -1
- views/questions_screen.py +15 -12
app.py
CHANGED
@@ -1,13 +1,8 @@
|
|
1 |
import json
|
2 |
from typing import Dict
|
3 |
-
|
4 |
-
from
|
5 |
-
|
6 |
-
from db.schema import Feedback, Response
|
7 |
-
from db.crud import ingest, read, save_feedback
|
8 |
-
import pandas as pd
|
9 |
import streamlit as st
|
10 |
-
from datetime import datetime
|
11 |
import os
|
12 |
from dotenv import load_dotenv
|
13 |
from views.intro_screen import welcome_screen
|
@@ -18,6 +13,7 @@ from css.layout import custom_css
|
|
18 |
load_dotenv()
|
19 |
VALIDATION_CODE = os.getenv("VALIDATION_CODE")
|
20 |
|
|
|
21 |
def initialization():
|
22 |
"""Initialize session state variables."""
|
23 |
if "current_index" not in st.session_state:
|
@@ -58,21 +54,6 @@ def reset_survey():
|
|
58 |
st.session_state.start_new_survey = True
|
59 |
|
60 |
|
61 |
-
def load_data():
|
62 |
-
try:
|
63 |
-
data = pd.read_csv("data/gemini_results_subset.csv")[:5]
|
64 |
-
return data
|
65 |
-
except Exception as e:
|
66 |
-
repo_name = os.getenv("DATA_REPO")
|
67 |
-
data_files = os.getenv("LLAMA_DATA_FILES")
|
68 |
-
print("data_files", data_files)
|
69 |
-
HF_TOKEN = os.getenv("HF_TOKEN")
|
70 |
-
dataset = load_dataset(repo_name, token=True, data_files=data_files, revision="main")
|
71 |
-
dataset.set_format(type='pandas') ## converting it into pandas
|
72 |
-
df = dataset["train"][:]
|
73 |
-
return df[:5]
|
74 |
-
|
75 |
-
|
76 |
def ui():
|
77 |
"""Main function to control the survey flow."""
|
78 |
custom_css()
|
|
|
1 |
import json
|
2 |
from typing import Dict
|
3 |
+
from utils.loaders import load_data
|
4 |
+
from db.crud import read
|
|
|
|
|
|
|
|
|
5 |
import streamlit as st
|
|
|
6 |
import os
|
7 |
from dotenv import load_dotenv
|
8 |
from views.intro_screen import welcome_screen
|
|
|
13 |
load_dotenv()
|
14 |
VALIDATION_CODE = os.getenv("VALIDATION_CODE")
|
15 |
|
16 |
+
|
17 |
def initialization():
|
18 |
"""Initialize session state variables."""
|
19 |
if "current_index" not in st.session_state:
|
|
|
54 |
st.session_state.start_new_survey = True
|
55 |
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
def ui():
|
58 |
"""Main function to control the survey flow."""
|
59 |
custom_css()
|
utils/loaders.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import os
|
3 |
+
|
4 |
+
from datasets import load_dataset
|
5 |
+
from dotenv import load_dotenv
|
6 |
+
|
7 |
+
load_dotenv()
|
8 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
9 |
+
REPO_NAME = os.getenv("DATA_REPO")
|
10 |
+
DATA_FILES = os.getenv("LLAMA_DATA_FILES")
|
11 |
+
|
12 |
+
|
13 |
+
def load_data():
|
14 |
+
try:
|
15 |
+
#TODO: change this to load the data from the database (buggy for debugging)
|
16 |
+
data = pd.read_csv("../data/gemini_results_subset.csv")[:5]
|
17 |
+
return data
|
18 |
+
except Exception as e:
|
19 |
+
|
20 |
+
print("data not found, loading from huggingface dataset")
|
21 |
+
|
22 |
+
dataset = load_dataset(REPO_NAME, token=True, data_files=DATA_FILES, revision="main")
|
23 |
+
dataset.set_format(type='pandas') ## converting it into pandas
|
24 |
+
df = dataset["train"][:]
|
25 |
+
return df[:5]
|
views/nav_buttons.py
CHANGED
@@ -38,7 +38,7 @@ def navigation_buttons(data, ratings_v, ratings_p0, ratings_p1):
|
|
38 |
|
39 |
col1, col2, col3 = st.columns([1, 1, 2])
|
40 |
|
41 |
-
with col1: # Back button
|
42 |
if st.button("Back") and current_index > 0:
|
43 |
st.session_state.current_index -= 1
|
44 |
st.rerun()
|
|
|
38 |
|
39 |
col1, col2, col3 = st.columns([1, 1, 2])
|
40 |
|
41 |
+
with col1: # Back button #TODO fix
|
42 |
if st.button("Back") and current_index > 0:
|
43 |
st.session_state.current_index -= 1
|
44 |
st.rerun()
|
views/questions_screen.py
CHANGED
@@ -1,7 +1,4 @@
|
|
1 |
-
import
|
2 |
-
from typing import Dict
|
3 |
-
|
4 |
-
from db.schema import Feedback, Response
|
5 |
import streamlit as st
|
6 |
from datetime import datetime
|
7 |
import os
|
@@ -9,7 +6,17 @@ from dotenv import load_dotenv
|
|
9 |
from views.nav_buttons import navigation_buttons
|
10 |
|
11 |
load_dotenv()
|
12 |
-
VALIDATION_CODE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
|
15 |
def survey_completed():
|
@@ -30,7 +37,7 @@ def render_query_ratings(query_label, config, query_key, current_index, has_pers
|
|
30 |
"""Helper function to render ratings for a given query."""
|
31 |
st.markdown(f"### {query_label}")
|
32 |
st.write(config[query_key])
|
33 |
-
columns = st.columns(3 if has_persona_alignment else 2)
|
34 |
columns = st.columns(3)
|
35 |
options = [0, 1, 2, 3, 4]
|
36 |
|
@@ -47,16 +54,13 @@ def render_query_ratings(query_label, config, query_key, current_index, has_pers
|
|
47 |
relevance_rating = st.radio("Relevance:",
|
48 |
options, key=f"rating_{query_key}_relevance_{current_index}",
|
49 |
format_func=lambda x:
|
50 |
-
["N/A", "Not Relevant", "Somewhat Relevant", "Relevant", "Unclear"][x],)
|
51 |
with columns[2]:
|
52 |
clarity_rating = st.radio("Clarity:",
|
53 |
-
options
|
54 |
key=f"rating_{query_key}_clarity_{current_index}",
|
55 |
format_func=lambda x: ["N/A", "Not Clear", "Somewhat Clear", "Very Clear"][x])
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
return {
|
61 |
"clarity": clarity_rating,
|
62 |
"relevance": relevance_rating,
|
@@ -117,4 +121,3 @@ def questions_screen(data):
|
|
117 |
navigation_buttons(data, query_v_ratings["clarity"], query_p0_ratings["clarity"], query_p1_ratings["clarity"])
|
118 |
except IndexError:
|
119 |
print("Survey completed!")
|
120 |
-
|
|
|
1 |
+
from db.schema import Response
|
|
|
|
|
|
|
2 |
import streamlit as st
|
3 |
from datetime import datetime
|
4 |
import os
|
|
|
6 |
from views.nav_buttons import navigation_buttons
|
7 |
|
8 |
load_dotenv()
|
9 |
+
if "VALIDATION_CODE" in os.environ:
|
10 |
+
VALIDATION_CODE = os.getenv("VALIDATION_CODE")
|
11 |
+
if "DATA_REPO" in os.environ:
|
12 |
+
REPO_NAME = os.getenv("DATA_REPO")
|
13 |
+
else:
|
14 |
+
print("DATA_REPO not found in environment variables.")
|
15 |
+
if "LLAMA_DATA_FILES" in os.environ:
|
16 |
+
DATA_FILES = os.getenv("LLAMA_DATA_FILES")
|
17 |
+
else:
|
18 |
+
print("LLAMA_DATA_FILES not found in environment variables.")
|
19 |
+
|
20 |
|
21 |
|
22 |
def survey_completed():
|
|
|
37 |
"""Helper function to render ratings for a given query."""
|
38 |
st.markdown(f"### {query_label}")
|
39 |
st.write(config[query_key])
|
40 |
+
# columns = st.columns(3 if has_persona_alignment else 2)
|
41 |
columns = st.columns(3)
|
42 |
options = [0, 1, 2, 3, 4]
|
43 |
|
|
|
54 |
relevance_rating = st.radio("Relevance:",
|
55 |
options, key=f"rating_{query_key}_relevance_{current_index}",
|
56 |
format_func=lambda x:
|
57 |
+
["N/A", "Not Relevant", "Somewhat Relevant", "Relevant", "Unclear"][x], )
|
58 |
with columns[2]:
|
59 |
clarity_rating = st.radio("Clarity:",
|
60 |
+
options=[0, 1, 2, 3],
|
61 |
key=f"rating_{query_key}_clarity_{current_index}",
|
62 |
format_func=lambda x: ["N/A", "Not Clear", "Somewhat Clear", "Very Clear"][x])
|
63 |
|
|
|
|
|
|
|
64 |
return {
|
65 |
"clarity": clarity_rating,
|
66 |
"relevance": relevance_rating,
|
|
|
121 |
navigation_buttons(data, query_v_ratings["clarity"], query_p0_ratings["clarity"], query_p1_ratings["clarity"])
|
122 |
except IndexError:
|
123 |
print("Survey completed!")
|
|