Upload folder using huggingface_hub
Browse files- advanced_rag.py +11 -4
advanced_rag.py
CHANGED
|
@@ -317,10 +317,10 @@ def cleanup_old_jobs():
|
|
| 317 |
to_delete = []
|
| 318 |
|
| 319 |
for job_id, job in jobs.items():
|
| 320 |
-
# Keep completed jobs for
|
| 321 |
-
if job["status"] == "completed" and (current_time - job.get("end_time", 0)) >
|
| 322 |
to_delete.append(job_id)
|
| 323 |
-
elif job["status"] == "processing" and (current_time - job.get("start_time", 0)) >
|
| 324 |
to_delete.append(job_id)
|
| 325 |
|
| 326 |
for job_id in to_delete:
|
|
@@ -867,6 +867,8 @@ def run_query(max_value):
|
|
| 867 |
|
| 868 |
# Function to call both refresh_job_list and check_job_status using the last job ID
|
| 869 |
def periodic_update(is_checked):
|
|
|
|
|
|
|
| 870 |
if is_checked:
|
| 871 |
global last_job_id
|
| 872 |
job_list_md = refresh_job_list()
|
|
@@ -875,8 +877,13 @@ def periodic_update(is_checked):
|
|
| 875 |
context_info = rag_chain.get_current_context() if rag_chain else "No context available."
|
| 876 |
return job_list_md, job_status[0], query_results, context_info
|
| 877 |
else:
|
|
|
|
| 878 |
return "", "", [], ""
|
| 879 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 880 |
# Update the Gradio interface to include job status checking
|
| 881 |
with gr.Blocks(css=custom_css, js="""
|
| 882 |
document.addEventListener('DOMContentLoaded', function() {
|
|
@@ -1160,7 +1167,7 @@ https://www.gutenberg.org/ebooks/8438.txt.utf-8
|
|
| 1160 |
fn=periodic_update,
|
| 1161 |
inputs=[auto_refresh_checkbox],
|
| 1162 |
outputs=[job_list, status_response, df, status_context],
|
| 1163 |
-
every=2
|
| 1164 |
)
|
| 1165 |
|
| 1166 |
if __name__ == "__main__":
|
|
|
|
| 317 |
to_delete = []
|
| 318 |
|
| 319 |
for job_id, job in jobs.items():
|
| 320 |
+
# Keep completed jobs for 24 hours, processing jobs for 48 hours
|
| 321 |
+
if job["status"] == "completed" and (current_time - job.get("end_time", 0)) > 86400:
|
| 322 |
to_delete.append(job_id)
|
| 323 |
+
elif job["status"] == "processing" and (current_time - job.get("start_time", 0)) > 172800:
|
| 324 |
to_delete.append(job_id)
|
| 325 |
|
| 326 |
for job_id in to_delete:
|
|
|
|
| 867 |
|
| 868 |
# Function to call both refresh_job_list and check_job_status using the last job ID
|
| 869 |
def periodic_update(is_checked):
|
| 870 |
+
interval = 2 if is_checked else None
|
| 871 |
+
debug_print(f"Auto-refresh checkbox is {'checked' if is_checked else 'unchecked'}, every={interval}")
|
| 872 |
if is_checked:
|
| 873 |
global last_job_id
|
| 874 |
job_list_md = refresh_job_list()
|
|
|
|
| 877 |
context_info = rag_chain.get_current_context() if rag_chain else "No context available."
|
| 878 |
return job_list_md, job_status[0], query_results, context_info
|
| 879 |
else:
|
| 880 |
+
# Return empty values to stop updates
|
| 881 |
return "", "", [], ""
|
| 882 |
|
| 883 |
+
# Define a function to determine the interval based on the checkbox state
|
| 884 |
+
def get_interval(is_checked):
|
| 885 |
+
return 2 if is_checked else None
|
| 886 |
+
|
| 887 |
# Update the Gradio interface to include job status checking
|
| 888 |
with gr.Blocks(css=custom_css, js="""
|
| 889 |
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
| 1167 |
fn=periodic_update,
|
| 1168 |
inputs=[auto_refresh_checkbox],
|
| 1169 |
outputs=[job_list, status_response, df, status_context],
|
| 1170 |
+
every=2 #if auto_refresh_checkbox.value else None # Directly set `every` based on the checkbox state
|
| 1171 |
)
|
| 1172 |
|
| 1173 |
if __name__ == "__main__":
|