Update app.py
Browse files
app.py
CHANGED
@@ -106,9 +106,9 @@ def save_choice(text_id, original_text, summary_a, summary_b, choice, notes=""):
|
|
106 |
success, message = push_to_hf_dataset(new_row)
|
107 |
|
108 |
if success:
|
109 |
-
return f"
|
110 |
else:
|
111 |
-
return f"
|
112 |
|
113 |
class SummaryChooser:
|
114 |
def __init__(self):
|
@@ -159,119 +159,38 @@ class SummaryChooser:
|
|
159 |
def get_hf_status(self):
|
160 |
"""Get the status of HuggingFace integration"""
|
161 |
success, message = self.hf_status
|
162 |
-
return f"
|
163 |
-
|
164 |
-
def select_summary_a(self):
|
165 |
-
"""Helper function to select Summary A"""
|
166 |
-
return "Summary A"
|
167 |
-
|
168 |
-
def select_summary_b(self):
|
169 |
-
"""Helper function to select Summary B"""
|
170 |
-
return "Summary B"
|
171 |
|
172 |
# Create the application
|
173 |
app = SummaryChooser()
|
174 |
|
175 |
-
# Custom CSS for clickable summaries
|
176 |
-
css = """
|
177 |
-
.clickable-summary {
|
178 |
-
border: 1px solid #ddd;
|
179 |
-
border-radius: 8px;
|
180 |
-
padding: 16px;
|
181 |
-
cursor: pointer;
|
182 |
-
transition: all 0.3s;
|
183 |
-
height: 100%;
|
184 |
-
}
|
185 |
-
.clickable-summary:hover {
|
186 |
-
border-color: #2196F3;
|
187 |
-
box-shadow: 0 0 10px rgba(33, 150, 243, 0.3);
|
188 |
-
}
|
189 |
-
.clickable-summary.selected {
|
190 |
-
border-color: #2196F3;
|
191 |
-
background-color: rgba(33, 150, 243, 0.1);
|
192 |
-
box-shadow: 0 0 10px rgba(33, 150, 243, 0.5);
|
193 |
-
}
|
194 |
-
.info-box {
|
195 |
-
padding: 8px 12px;
|
196 |
-
border-radius: 4px;
|
197 |
-
background-color: #f5f5f5;
|
198 |
-
border: 1px solid #ddd;
|
199 |
-
font-size: 14px;
|
200 |
-
flex: 1;
|
201 |
-
margin: 0 4px;
|
202 |
-
}
|
203 |
-
.status-container {
|
204 |
-
display: flex;
|
205 |
-
justify-content: space-between;
|
206 |
-
align-items: center;
|
207 |
-
margin-bottom: 12px;
|
208 |
-
}
|
209 |
-
"""
|
210 |
-
|
211 |
# Define the Gradio interface
|
212 |
-
with gr.Blocks(title="Summary Chooser"
|
213 |
gr.Markdown("# Summary Comparison Tool")
|
214 |
-
gr.Markdown("Choose the better summary for each text
|
215 |
-
|
216 |
-
# Hidden variable to track the selection
|
217 |
-
selected_summary = gr.Radio(
|
218 |
-
choices=["Summary A", "Summary B"],
|
219 |
-
label="Selected Summary",
|
220 |
-
visible=False
|
221 |
-
)
|
222 |
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
hf_status = gr.Textbox(label="Status", value=app.get_hf_status(), interactive=False, elem_classes=["info-box"])
|
231 |
|
232 |
with gr.Row():
|
233 |
text_box = gr.TextArea(label="Original Text", lines=8)
|
234 |
|
235 |
-
|
236 |
-
with gr.Row(equal_height=True):
|
237 |
with gr.Column():
|
238 |
-
|
239 |
-
summary_a_title = gr.Markdown("### Summary A")
|
240 |
-
summary_a = gr.TextArea(label="", lines=5, interactive=False)
|
241 |
-
|
242 |
with gr.Column():
|
243 |
-
|
244 |
-
summary_b_title = gr.Markdown("### Summary B")
|
245 |
-
summary_b = gr.TextArea(label="", lines=5, interactive=False)
|
246 |
-
|
247 |
-
# Client-side JavaScript for clickable behavior
|
248 |
-
summary_a_box.click(
|
249 |
-
fn=app.select_summary_a,
|
250 |
-
inputs=[],
|
251 |
-
outputs=[selected_summary],
|
252 |
-
_js="""
|
253 |
-
() => {
|
254 |
-
// Add selected class to summary A and remove from summary B
|
255 |
-
document.querySelectorAll('.clickable-summary')[0].classList.add('selected');
|
256 |
-
document.querySelectorAll('.clickable-summary')[1].classList.remove('selected');
|
257 |
-
return "Summary A";
|
258 |
-
}
|
259 |
-
"""
|
260 |
-
)
|
261 |
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
() => {
|
268 |
-
// Add selected class to summary B and remove from summary A
|
269 |
-
document.querySelectorAll('.clickable-summary')[1].classList.add('selected');
|
270 |
-
document.querySelectorAll('.clickable-summary')[0].classList.remove('selected');
|
271 |
-
return "Summary B";
|
272 |
-
}
|
273 |
-
"""
|
274 |
-
)
|
275 |
|
276 |
with gr.Row():
|
277 |
notes_box = gr.TextArea(label="Notes (optional)", lines=2)
|
@@ -294,32 +213,14 @@ with gr.Blocks(title="Summary Chooser", css=css) as interface:
|
|
294 |
# Set up event handlers
|
295 |
submit_button.click(
|
296 |
fn=app.next_item,
|
297 |
-
inputs=[
|
298 |
-
outputs=[text_id_box, text_box, summary_a, summary_b, progress_label, result_box]
|
299 |
-
_js="""
|
300 |
-
function(choice, notes) {
|
301 |
-
// Reset selection highlight
|
302 |
-
document.querySelectorAll('.clickable-summary').forEach(el => {
|
303 |
-
el.classList.remove('selected');
|
304 |
-
});
|
305 |
-
return [choice, notes];
|
306 |
-
}
|
307 |
-
"""
|
308 |
)
|
309 |
|
310 |
prev_button.click(
|
311 |
fn=app.prev_item,
|
312 |
inputs=[],
|
313 |
-
outputs=[text_id_box, text_box, summary_a, summary_b, progress_label, result_box]
|
314 |
-
_js="""
|
315 |
-
function() {
|
316 |
-
// Reset selection highlight
|
317 |
-
document.querySelectorAll('.clickable-summary').forEach(el => {
|
318 |
-
el.classList.remove('selected');
|
319 |
-
});
|
320 |
-
return [];
|
321 |
-
}
|
322 |
-
"""
|
323 |
)
|
324 |
|
325 |
# Launch the application
|
|
|
106 |
success, message = push_to_hf_dataset(new_row)
|
107 |
|
108 |
if success:
|
109 |
+
return f"Selection saved for text ID: {text_id}! You chose {'Summary A' if choice == 'Summary A' else 'Summary B'}. Pushed to HuggingFace."
|
110 |
else:
|
111 |
+
return f"Selection saved locally for text ID: {text_id}. HuggingFace push failed: {message}"
|
112 |
|
113 |
class SummaryChooser:
|
114 |
def __init__(self):
|
|
|
159 |
def get_hf_status(self):
|
160 |
"""Get the status of HuggingFace integration"""
|
161 |
success, message = self.hf_status
|
162 |
+
return f"HuggingFace Status: {'Connected' if success else 'Not Connected'} - {message}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
|
164 |
# Create the application
|
165 |
app = SummaryChooser()
|
166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
# Define the Gradio interface
|
168 |
+
with gr.Blocks(title="Summary Chooser") as interface:
|
169 |
gr.Markdown("# Summary Comparison Tool")
|
170 |
+
gr.Markdown("Choose the better summary for each text")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
|
172 |
+
with gr.Row():
|
173 |
+
with gr.Column():
|
174 |
+
progress_label = gr.Label(label="Progress")
|
175 |
+
with gr.Column():
|
176 |
+
hf_status = gr.Label(label="HuggingFace Status", value=app.get_hf_status())
|
177 |
+
with gr.Column():
|
178 |
+
text_id_box = gr.Textbox(label="Text ID", interactive=False)
|
|
|
179 |
|
180 |
with gr.Row():
|
181 |
text_box = gr.TextArea(label="Original Text", lines=8)
|
182 |
|
183 |
+
with gr.Row():
|
|
|
184 |
with gr.Column():
|
185 |
+
summary_a = gr.TextArea(label="Summary A", lines=5)
|
|
|
|
|
|
|
186 |
with gr.Column():
|
187 |
+
summary_b = gr.TextArea(label="Summary B", lines=5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
|
189 |
+
with gr.Row():
|
190 |
+
choice_radio = gr.Radio(
|
191 |
+
choices=["Summary A", "Summary B"],
|
192 |
+
label="Select the better summary"
|
193 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
|
195 |
with gr.Row():
|
196 |
notes_box = gr.TextArea(label="Notes (optional)", lines=2)
|
|
|
213 |
# Set up event handlers
|
214 |
submit_button.click(
|
215 |
fn=app.next_item,
|
216 |
+
inputs=[choice_radio, notes_box],
|
217 |
+
outputs=[text_id_box, text_box, summary_a, summary_b, progress_label, result_box]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
)
|
219 |
|
220 |
prev_button.click(
|
221 |
fn=app.prev_item,
|
222 |
inputs=[],
|
223 |
+
outputs=[text_id_box, text_box, summary_a, summary_b, progress_label, result_box]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
)
|
225 |
|
226 |
# Launch the application
|