update: Enhance reaction saving functionality by adding user type selection and updating dataset path
Browse files
app.py
CHANGED
@@ -12,22 +12,22 @@ def load_data(database_file):
|
|
12 |
chunk_embeddings[idx] = t.tensor(df.loc[df.index[idx], "chunk_embeddings"])
|
13 |
return df, chunk_embeddings
|
14 |
|
15 |
-
def save_reactions_to_dataset(query, results):
|
16 |
data = {
|
|
|
17 |
"query": [],
|
18 |
"retrieved_text": [],
|
19 |
-
"score": [],
|
20 |
"reaction": []
|
21 |
}
|
22 |
|
23 |
for result in results:
|
|
|
24 |
data["query"].append(query)
|
25 |
data["retrieved_text"].append(result["text"])
|
26 |
-
data["score"].append(result["score"].item())
|
27 |
data["reaction"].append(result["reaction"])
|
28 |
|
29 |
dataset = Dataset.from_dict(data)
|
30 |
-
dataset.save_to_disk("al-ghazali-rag-retrieval-evaluation")
|
31 |
|
32 |
def main():
|
33 |
st.title("Semantic Text Retrieval Evaluation Interface")
|
@@ -46,6 +46,13 @@ def main():
|
|
46 |
df, chunk_embeddings = load_data(database_file)
|
47 |
st.success("Database loaded successfully!")
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
query = st.text_area("Enter your query:")
|
50 |
|
51 |
if st.button("Search") and query:
|
@@ -66,21 +73,21 @@ def main():
|
|
66 |
|
67 |
results = []
|
68 |
|
69 |
-
for
|
70 |
text = df.iloc[int(idx)]["ext"]
|
71 |
-
st.write(f"### Score: {score:.4f}")
|
72 |
st.write(f"**Text:** {text}")
|
73 |
|
74 |
reaction = st.radio(
|
75 |
label="Rate this result:",
|
76 |
options=["π", "π€·", "π"],
|
|
|
77 |
key=f"reaction_{idx}",
|
78 |
)
|
79 |
|
80 |
-
results.append({"text": text, "
|
81 |
|
82 |
if st.button("Save Reactions"):
|
83 |
-
save_reactions_to_dataset(query, results)
|
84 |
st.success("Reactions saved successfully!")
|
85 |
|
86 |
except Exception as e:
|
|
|
12 |
chunk_embeddings[idx] = t.tensor(df.loc[df.index[idx], "chunk_embeddings"])
|
13 |
return df, chunk_embeddings
|
14 |
|
15 |
+
def save_reactions_to_dataset(user_type, query, results):
|
16 |
data = {
|
17 |
+
"user_type": [],
|
18 |
"query": [],
|
19 |
"retrieved_text": [],
|
|
|
20 |
"reaction": []
|
21 |
}
|
22 |
|
23 |
for result in results:
|
24 |
+
data["user_type"].append(user_type)
|
25 |
data["query"].append(query)
|
26 |
data["retrieved_text"].append(result["text"])
|
|
|
27 |
data["reaction"].append(result["reaction"])
|
28 |
|
29 |
dataset = Dataset.from_dict(data)
|
30 |
+
dataset.save_to_disk("HumbleBeeAI/al-ghazali-rag-retrieval-evaluation")
|
31 |
|
32 |
def main():
|
33 |
st.title("Semantic Text Retrieval Evaluation Interface")
|
|
|
46 |
df, chunk_embeddings = load_data(database_file)
|
47 |
st.success("Database loaded successfully!")
|
48 |
|
49 |
+
# Select user type
|
50 |
+
user_type = st.radio(
|
51 |
+
"Select your user type:",
|
52 |
+
["Layman", "Enthusiast", "Ustaz (Expert)"],
|
53 |
+
horizontal=True
|
54 |
+
)
|
55 |
+
|
56 |
query = st.text_area("Enter your query:")
|
57 |
|
58 |
if st.button("Search") and query:
|
|
|
73 |
|
74 |
results = []
|
75 |
|
76 |
+
for _, idx in zip(top_results_dot_product[0], top_results_dot_product[1]):
|
77 |
text = df.iloc[int(idx)]["ext"]
|
|
|
78 |
st.write(f"**Text:** {text}")
|
79 |
|
80 |
reaction = st.radio(
|
81 |
label="Rate this result:",
|
82 |
options=["π", "π€·", "π"],
|
83 |
+
index=1, # Default to neutral emoji
|
84 |
key=f"reaction_{idx}",
|
85 |
)
|
86 |
|
87 |
+
results.append({"text": text, "reaction": reaction})
|
88 |
|
89 |
if st.button("Save Reactions"):
|
90 |
+
save_reactions_to_dataset(user_type, query, results)
|
91 |
st.success("Reactions saved successfully!")
|
92 |
|
93 |
except Exception as e:
|