Added all the answers
Browse files
app.py
CHANGED
|
@@ -51,31 +51,54 @@ def process_query(query):
|
|
| 51 |
tf_idf_ranking_modified, bm25_ranking_modified, open_source_ranking_modified
|
| 52 |
)
|
| 53 |
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
boolean_context = miniWikiCollectionDict[boolean_ranking[0]]
|
| 56 |
tf_idf_context = miniWikiCollectionDict[tf_idf_ranking[0]]
|
| 57 |
bm25_context = miniWikiCollectionDict[str(bm25_ranking[0])]
|
| 58 |
vision_context = miniWikiCollectionDict[vision_ranking[0]]
|
| 59 |
open_source_context = miniWikiCollectionDict[open_source_ranking[0]]
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
tf_idf_bm25_open_RRF_Ranking_context = miniWikiCollectionDict[tf_idf_bm25_open_RRF_Ranking[0]]
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
agent2_context = article
|
| 66 |
|
| 67 |
agent1_answer = generate_answer_withContext(query, agent1_context)
|
| 68 |
agent2_answer = generate_answer_withContext(query, agent2_context)
|
|
|
|
| 69 |
boolean_answer = generate_answer_withContext(query, boolean_context)
|
| 70 |
tf_idf_answer = generate_answer_withContext(query, tf_idf_context)
|
| 71 |
bm25_answer = generate_answer_withContext(query, bm25_context)
|
| 72 |
vision_answer = generate_answer_withContext(query, vision_context)
|
| 73 |
open_source_answer = generate_answer_withContext(query, open_source_context)
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
tf_idf_bm25_open_RRF_Ranking_answer = generate_answer_withContext(query, tf_idf_bm25_open_RRF_Ranking_context)
|
|
|
|
|
|
|
| 76 |
|
| 77 |
zeroShot = generate_answer_zeroShot(query)
|
| 78 |
|
|
|
|
| 79 |
# Ranking the best answer
|
| 80 |
rankerAgentInput = {
|
| 81 |
"query": query,
|
|
@@ -86,27 +109,96 @@ def process_query(query):
|
|
| 86 |
"bm25": bm25_answer,
|
| 87 |
"vision": vision_answer,
|
| 88 |
"open_source": open_source_answer,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
"tf_idf_bm25_open_RRF_Ranking": tf_idf_bm25_open_RRF_Ranking_answer,
|
| 90 |
-
"
|
|
|
|
|
|
|
| 91 |
}
|
| 92 |
|
| 93 |
best_model, best_answer = rankerAgent(rankerAgentInput)
|
| 94 |
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
# Gradio interface
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
gr.Textbox(label="
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
)
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
if __name__ == "__main__":
|
| 112 |
-
|
|
|
|
| 51 |
tf_idf_ranking_modified, bm25_ranking_modified, open_source_ranking_modified
|
| 52 |
)
|
| 53 |
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
agent1_context = wiki_data[0]
|
| 58 |
+
agent2_context = article
|
| 59 |
+
|
| 60 |
boolean_context = miniWikiCollectionDict[boolean_ranking[0]]
|
| 61 |
tf_idf_context = miniWikiCollectionDict[tf_idf_ranking[0]]
|
| 62 |
bm25_context = miniWikiCollectionDict[str(bm25_ranking[0])]
|
| 63 |
vision_context = miniWikiCollectionDict[vision_ranking[0]]
|
| 64 |
open_source_context = miniWikiCollectionDict[open_source_ranking[0]]
|
| 65 |
|
| 66 |
+
boolean_context_modified = miniWikiCollectionDict[boolean_ranking_modified[0]]
|
| 67 |
+
tf_idf_context_modified = miniWikiCollectionDict[tf_idf_ranking_modified[0]]
|
| 68 |
+
bm25_context = miniWikiCollectionDict[str(bm25_ranking_modified[0])]
|
| 69 |
+
vision_context_modified = miniWikiCollectionDict[vision_ranking_modified[0]]
|
| 70 |
+
open_source_context_modified = miniWikiCollectionDict[open_source_ranking_modified[0]]
|
| 71 |
+
|
| 72 |
tf_idf_bm25_open_RRF_Ranking_context = miniWikiCollectionDict[tf_idf_bm25_open_RRF_Ranking[0]]
|
| 73 |
+
tf_idf_bm25_open_RRF_Ranking_modified_context = miniWikiCollectionDict[tf_idf_bm25_open_RRF_Ranking_modified[0]]
|
| 74 |
+
tf_idf_bm25_open_RRF_Ranking_combined_context = miniWikiCollectionDict[tf_idf_bm25_open_RRF_Ranking_combined[0]]
|
| 75 |
+
|
| 76 |
|
| 77 |
+
|
| 78 |
+
#Generating answers
|
|
|
|
| 79 |
|
| 80 |
agent1_answer = generate_answer_withContext(query, agent1_context)
|
| 81 |
agent2_answer = generate_answer_withContext(query, agent2_context)
|
| 82 |
+
|
| 83 |
boolean_answer = generate_answer_withContext(query, boolean_context)
|
| 84 |
tf_idf_answer = generate_answer_withContext(query, tf_idf_context)
|
| 85 |
bm25_answer = generate_answer_withContext(query, bm25_context)
|
| 86 |
vision_answer = generate_answer_withContext(query, vision_context)
|
| 87 |
open_source_answer = generate_answer_withContext(query, open_source_context)
|
| 88 |
|
| 89 |
+
boolean_answer_modified = generate_answer_withContext(modified_query, boolean_context_modified)
|
| 90 |
+
tf_idf_answer_modified = generate_answer_withContext(modified_query, tf_idf_context_modified)
|
| 91 |
+
bm25_answer_modified = generate_answer_withContext(modified_query, bm25_context)
|
| 92 |
+
vision_answer_modified = generate_answer_withContext(modified_query, vision_context_modified)
|
| 93 |
+
open_source_answer_modified = generate_answer_withContext(modified_query, open_source_context_modified)
|
| 94 |
+
|
| 95 |
tf_idf_bm25_open_RRF_Ranking_answer = generate_answer_withContext(query, tf_idf_bm25_open_RRF_Ranking_context)
|
| 96 |
+
tf_idf_bm25_open_RRF_Ranking_modified_answer = generate_answer_withContext(modified_query, tf_idf_bm25_open_RRF_Ranking_modified_context)
|
| 97 |
+
tf_idf_bm25_open_RRF_Ranking_combined_answer = generate_answer_withContext(query, tf_idf_bm25_open_RRF_Ranking_combined_context)
|
| 98 |
|
| 99 |
zeroShot = generate_answer_zeroShot(query)
|
| 100 |
|
| 101 |
+
|
| 102 |
# Ranking the best answer
|
| 103 |
rankerAgentInput = {
|
| 104 |
"query": query,
|
|
|
|
| 109 |
"bm25": bm25_answer,
|
| 110 |
"vision": vision_answer,
|
| 111 |
"open_source": open_source_answer,
|
| 112 |
+
"boolean_modified": boolean_answer_modified,
|
| 113 |
+
"tf_idf_modified": tf_idf_answer_modified,
|
| 114 |
+
"bm25_modified": bm25_answer_modified,
|
| 115 |
+
"vision_modified": vision_answer_modified,
|
| 116 |
+
"open_source_modified": open_source_answer_modified,
|
| 117 |
"tf_idf_bm25_open_RRF_Ranking": tf_idf_bm25_open_RRF_Ranking_answer,
|
| 118 |
+
"tf_idf_bm25_open_RRF_Ranking_modified": tf_idf_bm25_open_RRF_Ranking_modified_answer,
|
| 119 |
+
"tf_idf_bm25_open_RRF_Ranking_combined": tf_idf_bm25_open_RRF_Ranking_combined_answer,
|
| 120 |
+
"zeroShot": zeroShot
|
| 121 |
}
|
| 122 |
|
| 123 |
best_model, best_answer = rankerAgent(rankerAgentInput)
|
| 124 |
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
all_answers = {
|
| 128 |
+
"Agent 1": agent1_answer,
|
| 129 |
+
"Agent 2": agent2_answer,
|
| 130 |
+
"Boolean": boolean_answer,
|
| 131 |
+
"TF-IDF": tf_idf_answer,
|
| 132 |
+
"BM25": bm25_answer,
|
| 133 |
+
"Vision": vision_answer,
|
| 134 |
+
"Open Source": open_source_answer,
|
| 135 |
+
"Boolean (Modified)": boolean_answer_modified,
|
| 136 |
+
"TF-IDF (Modified)": tf_idf_answer_modified,
|
| 137 |
+
"BM25 (Modified)": bm25_answer_modified,
|
| 138 |
+
"Vision (Modified)": vision_answer_modified,
|
| 139 |
+
"Open Source (Modified)": open_source_answer_modified,
|
| 140 |
+
"TF-IDF + BM25 + Open RRF": tf_idf_bm25_open_RRF_Ranking_answer,
|
| 141 |
+
"TF-IDF + BM25 + Open RRF (Modified)": tf_idf_bm25_open_RRF_Ranking_modified_answer,
|
| 142 |
+
"TF-IDF + BM25 + Open RRF (Combined)": tf_idf_bm25_open_RRF_Ranking_combined_answer,
|
| 143 |
+
"Zero Shot": zeroShot,
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
return best_model, best_answer, all_answers
|
| 147 |
|
| 148 |
# Gradio interface
|
| 149 |
+
def create_interface():
|
| 150 |
+
with gr.Blocks() as interface:
|
| 151 |
+
gr.Markdown("# Query Answering System")
|
| 152 |
+
gr.Markdown("Enter a query to get the best model and the best answer using multiple retrieval models and ranking techniques.")
|
| 153 |
+
query_input = gr.Textbox(label="Enter your query")
|
| 154 |
+
|
| 155 |
+
with gr.Row():
|
| 156 |
+
best_model_output = gr.Textbox(label="Best Model")
|
| 157 |
+
best_answer_output = gr.Textbox(label="Best Answer")
|
| 158 |
+
|
| 159 |
+
gr.Markdown("---") # Horizontal line
|
| 160 |
+
|
| 161 |
+
gr.Markdown("## All Answers")
|
| 162 |
+
with gr.Row():
|
| 163 |
+
agent1_output = gr.Textbox(label="Agent 1")
|
| 164 |
+
agent2_output = gr.Textbox(label="Agent 2")
|
| 165 |
+
boolean_output = gr.Textbox(label="Boolean")
|
| 166 |
+
tf_idf_output = gr.Textbox(label="TF-IDF")
|
| 167 |
+
bm25_output = gr.Textbox(label="BM25")
|
| 168 |
+
|
| 169 |
+
with gr.Row():
|
| 170 |
+
vision_output = gr.Textbox(label="Vision")
|
| 171 |
+
open_source_output = gr.Textbox(label="Open Source")
|
| 172 |
+
boolean_mod_output = gr.Textbox(label="Boolean (Modified)")
|
| 173 |
+
tf_idf_mod_output = gr.Textbox(label="TF-IDF (Modified)")
|
| 174 |
+
bm25_mod_output = gr.Textbox(label="BM25 (Modified)")
|
| 175 |
+
|
| 176 |
+
with gr.Row():
|
| 177 |
+
vision_mod_output = gr.Textbox(label="Vision (Modified)")
|
| 178 |
+
open_source_mod_output = gr.Textbox(label="Open Source (Modified)")
|
| 179 |
+
tf_idf_rrf_output = gr.Textbox(label="TF-IDF + BM25 + Open RRF")
|
| 180 |
+
tf_idf_rrf_mod_output = gr.Textbox(label="TF-IDF + BM25 + Open RRF (Modified)")
|
| 181 |
+
tf_idf_rrf_combined_output = gr.Textbox(label="TF-IDF + BM25 + Open RRF (Combined)")
|
| 182 |
+
|
| 183 |
+
zero_shot_output = gr.Textbox(label="Zero Shot")
|
| 184 |
+
|
| 185 |
+
gr.Button("Submit").click(
|
| 186 |
+
fn=process_query,
|
| 187 |
+
inputs=query_input,
|
| 188 |
+
outputs=[
|
| 189 |
+
best_model_output,
|
| 190 |
+
best_answer_output,
|
| 191 |
+
agent1_output, agent2_output,
|
| 192 |
+
boolean_output, tf_idf_output, bm25_output,
|
| 193 |
+
vision_output, open_source_output,
|
| 194 |
+
boolean_mod_output, tf_idf_mod_output, bm25_mod_output,
|
| 195 |
+
vision_mod_output, open_source_mod_output,
|
| 196 |
+
tf_idf_rrf_output, tf_idf_rrf_mod_output,
|
| 197 |
+
tf_idf_rrf_combined_output, zero_shot_output,
|
| 198 |
+
]
|
| 199 |
+
)
|
| 200 |
+
|
| 201 |
+
return interface
|
| 202 |
+
|
| 203 |
if __name__ == "__main__":
|
| 204 |
+
create_interface().launch()
|