Spaces:
Running
on
Zero
Running
on
Zero
Update interruption method
Browse files
app.py
CHANGED
|
@@ -102,9 +102,10 @@ def weighted_sample_without_replacement(population, weights, k=2):
|
|
| 102 |
def load_context(set_interrupt=False):
|
| 103 |
if set_interrupt:
|
| 104 |
generation_interrupt.set()
|
| 105 |
-
time.sleep(0.
|
| 106 |
|
| 107 |
-
|
|
|
|
| 108 |
example = get_random_example()
|
| 109 |
|
| 110 |
context_desc = example.get('processed_context_desc', '')
|
|
@@ -148,6 +149,10 @@ def generate_model_summaries(example):
|
|
| 148 |
"completed": False
|
| 149 |
}
|
| 150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
if generation_interrupt.is_set():
|
| 152 |
return result
|
| 153 |
|
|
@@ -180,12 +185,16 @@ def generate_model_summaries(example):
|
|
| 180 |
result["model_a"] = m_a_name
|
| 181 |
result["model_b"] = m_b_name
|
| 182 |
|
|
|
|
| 183 |
s_a, s_b = generate_summaries(example, m_a_name, m_b_name)
|
| 184 |
|
| 185 |
if not generation_interrupt.is_set():
|
| 186 |
result["summary_a"] = s_a
|
| 187 |
result["summary_b"] = s_b
|
| 188 |
result["completed"] = bool(s_a and s_b)
|
|
|
|
|
|
|
|
|
|
| 189 |
except Exception as e:
|
| 190 |
print(f"Error in generation: {e}")
|
| 191 |
|
|
@@ -334,7 +343,7 @@ def show_all_after_loading():
|
|
| 334 |
gr.update(visible=True), # model_section
|
| 335 |
gr.update(visible=True), # voting_section
|
| 336 |
gr.update(visible=True), # submit_button
|
| 337 |
-
gr.update(value="🔄 Try a New Question", elem_classes=["query-button"]) # update button text
|
| 338 |
]
|
| 339 |
|
| 340 |
with gr.Blocks(theme=gr.themes.Default(
|
|
|
|
| 102 |
def load_context(set_interrupt=False):
|
| 103 |
if set_interrupt:
|
| 104 |
generation_interrupt.set()
|
| 105 |
+
time.sleep(0.5) # Give more time for interrupt to take effect
|
| 106 |
|
| 107 |
+
# DON'T clear the interrupt here - let the new inference clear it
|
| 108 |
+
# generation_interrupt.clear() # REMOVED THIS LINE
|
| 109 |
example = get_random_example()
|
| 110 |
|
| 111 |
context_desc = example.get('processed_context_desc', '')
|
|
|
|
| 149 |
"completed": False
|
| 150 |
}
|
| 151 |
|
| 152 |
+
# Clear the interrupt flag when NEW inference starts
|
| 153 |
+
generation_interrupt.clear()
|
| 154 |
+
print("Interrupt flag cleared for new inference")
|
| 155 |
+
|
| 156 |
if generation_interrupt.is_set():
|
| 157 |
return result
|
| 158 |
|
|
|
|
| 185 |
result["model_a"] = m_a_name
|
| 186 |
result["model_b"] = m_b_name
|
| 187 |
|
| 188 |
+
print(f"Starting generation with models: {m_a_name} vs {m_b_name}")
|
| 189 |
s_a, s_b = generate_summaries(example, m_a_name, m_b_name)
|
| 190 |
|
| 191 |
if not generation_interrupt.is_set():
|
| 192 |
result["summary_a"] = s_a
|
| 193 |
result["summary_b"] = s_b
|
| 194 |
result["completed"] = bool(s_a and s_b)
|
| 195 |
+
print("Generation completed successfully")
|
| 196 |
+
else:
|
| 197 |
+
print("Generation was interrupted")
|
| 198 |
except Exception as e:
|
| 199 |
print(f"Error in generation: {e}")
|
| 200 |
|
|
|
|
| 343 |
gr.update(visible=True), # model_section
|
| 344 |
gr.update(visible=True), # voting_section
|
| 345 |
gr.update(visible=True), # submit_button
|
| 346 |
+
gr.update(value="🔄 Try a New Question", elem_classes=["query-button"], interactive=True) # update button text and re-enable
|
| 347 |
]
|
| 348 |
|
| 349 |
with gr.Blocks(theme=gr.themes.Default(
|