Updating UI
Browse files
app.py
CHANGED
@@ -51,10 +51,18 @@ def process_query(query):
|
|
51 |
tf_idf_ranking_modified, bm25_ranking_modified, open_source_ranking_modified
|
52 |
)
|
53 |
|
54 |
-
|
|
|
|
|
|
|
|
|
55 |
agent2_context = article
|
56 |
|
57 |
-
|
|
|
|
|
|
|
|
|
58 |
tf_idf_context = miniWikiCollectionDict[tf_idf_ranking[0]]
|
59 |
bm25_context = miniWikiCollectionDict[str(bm25_ranking[0])]
|
60 |
vision_context = miniWikiCollectionDict[vision_ranking[0]]
|
@@ -136,29 +144,85 @@ def process_query(query):
|
|
136 |
zeroShot, "Zero-shot doesn't have a context."
|
137 |
)
|
138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
# Interface creation
|
140 |
def create_interface():
|
141 |
with gr.Blocks() as interface:
|
142 |
-
|
143 |
-
best_model_output = gr.Textbox(label="Best Model", interactive=False)
|
144 |
-
best_answer_output = gr.Textbox(label="Best Answer", interactive=False)
|
145 |
-
|
146 |
-
def create_answer_row(label):
|
147 |
with gr.Row():
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
return answer_textbox, context_textbox
|
159 |
|
160 |
agent1_output, agent1_context_output = create_answer_row("Agent 1")
|
161 |
-
|
162 |
agent2_output, agent2_context_output = create_answer_row("Agent 2")
|
163 |
boolean_output, boolean_context_output = create_answer_row("Boolean")
|
164 |
tf_idf_output, tf_idf_context_output = create_answer_row("TF-IDF")
|
@@ -170,7 +234,7 @@ def create_interface():
|
|
170 |
tf_idf_mod_output, tf_idf_mod_context_output = create_answer_row("TF-IDF (Modified)")
|
171 |
bm25_mod_output, bm25_mod_context_output = create_answer_row("BM25 (Modified)")
|
172 |
vision_mod_output, vision_mod_context_output = create_answer_row("Vision (Modified)")
|
173 |
-
open_source_mod_output,
|
174 |
|
175 |
tf_idf_rrf_output, tf_idf_rrf_context_output = create_answer_row("TF-IDF + BM25 + Open RRF")
|
176 |
tf_idf_rrf_mod_output, tf_idf_rrf_mod_context_output = create_answer_row("TF-IDF + BM25 + Open RRF (Modified)")
|
@@ -178,7 +242,7 @@ def create_interface():
|
|
178 |
|
179 |
zero_shot_output, zero_shot_context_output = create_answer_row("Zero Shot")
|
180 |
|
181 |
-
|
182 |
fn=process_query,
|
183 |
inputs=query_input,
|
184 |
outputs=[
|
@@ -195,7 +259,7 @@ def create_interface():
|
|
195 |
tf_idf_mod_output, tf_idf_mod_context_output,
|
196 |
bm25_mod_output, bm25_mod_context_output,
|
197 |
vision_mod_output, vision_mod_context_output,
|
198 |
-
open_source_mod_output,
|
199 |
tf_idf_rrf_output, tf_idf_rrf_context_output,
|
200 |
tf_idf_rrf_mod_output, tf_idf_rrf_mod_context_output,
|
201 |
tf_idf_rrf_combined_output, tf_idf_rrf_combined_context_output,
|
@@ -208,4 +272,5 @@ def create_interface():
|
|
208 |
# Launch the interface
|
209 |
if __name__ == "__main__":
|
210 |
interface = create_interface()
|
|
|
211 |
interface.launch()
|
|
|
51 |
tf_idf_ranking_modified, bm25_ranking_modified, open_source_ranking_modified
|
52 |
)
|
53 |
|
54 |
+
try:
|
55 |
+
agent1_context = wiki_data[0]
|
56 |
+
except:
|
57 |
+
agent1_context = "Can't find a Wiki article for this query."
|
58 |
+
|
59 |
agent2_context = article
|
60 |
|
61 |
+
try:
|
62 |
+
boolean_context = miniWikiCollectionDict[boolean_ranking[0]]
|
63 |
+
except:
|
64 |
+
boolean_context = "Can't find a matching document for this query."
|
65 |
+
|
66 |
tf_idf_context = miniWikiCollectionDict[tf_idf_ranking[0]]
|
67 |
bm25_context = miniWikiCollectionDict[str(bm25_ranking[0])]
|
68 |
vision_context = miniWikiCollectionDict[vision_ranking[0]]
|
|
|
144 |
zeroShot, "Zero-shot doesn't have a context."
|
145 |
)
|
146 |
|
147 |
+
# CSS Styling for the fancy effects
|
148 |
+
css = """
|
149 |
+
#fancy-column {
|
150 |
+
background: linear-gradient(135deg, #1a242f, #2b3a44); /* Dark blue-gray gradient background */
|
151 |
+
padding: 20px;
|
152 |
+
border-radius: 15px;
|
153 |
+
}
|
154 |
+
|
155 |
+
#query-input, #submit-button, #best-model-output, #best-answer-output {
|
156 |
+
border-radius: 10px; /* Rounded corners */
|
157 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3); /* Darker shadow for better contrast */
|
158 |
+
background-color: #34495e; /* Dark background for inputs */
|
159 |
+
color: #ecf0f1; /* Light text for good readability */
|
160 |
+
}
|
161 |
+
|
162 |
+
#query-input:focus, #submit-button:focus, #best-model-output:focus, #best-answer-output:focus {
|
163 |
+
outline: none;
|
164 |
+
border: 2px solid #7f8c8d; /* Subtle accent border on focus */
|
165 |
+
}
|
166 |
+
|
167 |
+
#submit-button {
|
168 |
+
background-color: #16a085; /* Muted teal color for button */
|
169 |
+
color: #ecf0f1; /* Light text for button */
|
170 |
+
font-weight: bold;
|
171 |
+
padding: 10px;
|
172 |
+
}
|
173 |
+
|
174 |
+
#submit-button:hover {
|
175 |
+
background-color: #1abc9c; /* Slightly lighter teal on hover */
|
176 |
+
}
|
177 |
+
|
178 |
+
#best-model-output, #best-answer-output {
|
179 |
+
background-color: #2c3e50; /* Darker background for output boxes */
|
180 |
+
}
|
181 |
+
|
182 |
+
#best-model-output label, #best-answer-output label, #query-input label {
|
183 |
+
color: #ecf0f1; /* Light text for labels */
|
184 |
+
}
|
185 |
+
"""
|
186 |
+
|
187 |
+
|
188 |
+
|
189 |
# Interface creation
|
190 |
def create_interface():
|
191 |
with gr.Blocks() as interface:
|
192 |
+
with gr.Column(elem_id="fancy-column", scale=3): # Fancy column with extra styling
|
|
|
|
|
|
|
|
|
193 |
with gr.Row():
|
194 |
+
query_input = gr.Textbox(label="Enter your query", scale=3, elem_id="query-input")
|
195 |
+
submit_button = gr.Button("Submit", scale=1, elem_id="submit-button")
|
196 |
+
|
197 |
+
# Adjusting the spacing between the output fields
|
198 |
+
with gr.Row():
|
199 |
+
best_model_output = gr.Textbox(label="Best Model", interactive=False, scale=1.5, elem_id="best-model-output")
|
200 |
+
best_answer_output = gr.Textbox(label="Best Answer", interactive=False, scale=1.5, elem_id="best-answer-output")
|
201 |
+
|
202 |
+
with gr.Column():
|
203 |
+
# Function to create a row for answers and contexts
|
204 |
+
def create_answer_row(label):
|
205 |
+
if label == "Agent 1":
|
206 |
+
label = "Wiki Search"
|
207 |
+
elif label == "Agent 2":
|
208 |
+
label = "Llama Context Generation"
|
209 |
+
elif label == "Open Source Answer":
|
210 |
+
label = 'MiniLM Text Embedding model'
|
211 |
+
elif label == "Open Source (Modified)":
|
212 |
+
label = 'MiniLM Text Embedding model (Modified)'
|
213 |
+
elif label == "TF-IDF + BM25 + Open RRF":
|
214 |
+
label = "RRF (TF-IDF + BM25 + MiniLM)"
|
215 |
+
elif label == "TF-IDF + BM25 + Open RRF (Modified)":
|
216 |
+
label = "RRF (TF-IDF + BM25 + MiniLM) (Modified)"
|
217 |
+
elif label == "TF-IDF + BM25 + Open RRF (Combined)":
|
218 |
+
label = "RRF (TF-IDF + BM25 + MiniLM) (Combined)"
|
219 |
+
with gr.Row():
|
220 |
+
answer_textbox = gr.Textbox(label=f"{label} Answer", interactive=False, scale=1.2, elem_id="best-model-output")
|
221 |
+
context_textbox = gr.Textbox(label=f"{label} Context", scale=1.8, elem_id="best-answer-output")
|
222 |
+
|
223 |
return answer_textbox, context_textbox
|
224 |
|
225 |
agent1_output, agent1_context_output = create_answer_row("Agent 1")
|
|
|
226 |
agent2_output, agent2_context_output = create_answer_row("Agent 2")
|
227 |
boolean_output, boolean_context_output = create_answer_row("Boolean")
|
228 |
tf_idf_output, tf_idf_context_output = create_answer_row("TF-IDF")
|
|
|
234 |
tf_idf_mod_output, tf_idf_mod_context_output = create_answer_row("TF-IDF (Modified)")
|
235 |
bm25_mod_output, bm25_mod_context_output = create_answer_row("BM25 (Modified)")
|
236 |
vision_mod_output, vision_mod_context_output = create_answer_row("Vision (Modified)")
|
237 |
+
open_source_mod_output, open_source_mod_context_output = create_answer_row("Open Source (Modified)")
|
238 |
|
239 |
tf_idf_rrf_output, tf_idf_rrf_context_output = create_answer_row("TF-IDF + BM25 + Open RRF")
|
240 |
tf_idf_rrf_mod_output, tf_idf_rrf_mod_context_output = create_answer_row("TF-IDF + BM25 + Open RRF (Modified)")
|
|
|
242 |
|
243 |
zero_shot_output, zero_shot_context_output = create_answer_row("Zero Shot")
|
244 |
|
245 |
+
submit_button.click(
|
246 |
fn=process_query,
|
247 |
inputs=query_input,
|
248 |
outputs=[
|
|
|
259 |
tf_idf_mod_output, tf_idf_mod_context_output,
|
260 |
bm25_mod_output, bm25_mod_context_output,
|
261 |
vision_mod_output, vision_mod_context_output,
|
262 |
+
open_source_mod_output, open_source_mod_context_output,
|
263 |
tf_idf_rrf_output, tf_idf_rrf_context_output,
|
264 |
tf_idf_rrf_mod_output, tf_idf_rrf_mod_context_output,
|
265 |
tf_idf_rrf_combined_output, tf_idf_rrf_combined_context_output,
|
|
|
272 |
# Launch the interface
|
273 |
if __name__ == "__main__":
|
274 |
interface = create_interface()
|
275 |
+
interface.css = css
|
276 |
interface.launch()
|