Update app.py
Browse files
app.py
CHANGED
|
@@ -82,7 +82,7 @@ def submit_task(command, current_tasks):
|
|
| 82 |
with bucket_lock:
|
| 83 |
task_bucket.append(new_task)
|
| 84 |
current_tasks.append(new_task)
|
| 85 |
-
return current_tasks, generated_files, ""
|
| 86 |
|
| 87 |
def build_tasks_html(tasks):
|
| 88 |
"""
|
|
@@ -96,7 +96,7 @@ def build_tasks_html(tasks):
|
|
| 96 |
th, td {border: 1px solid #ddd; padding: 8px; text-align: left; font-size: 14px;}
|
| 97 |
th {background-color: #f2f2f2;}
|
| 98 |
.Complete {background-color: #d4edda;}
|
| 99 |
-
.In\ Progress {background-color: #fff3cd;}
|
| 100 |
.Pending {background-color: #f8d7da;}
|
| 101 |
</style>
|
| 102 |
<table>
|
|
@@ -139,6 +139,10 @@ def refresh_ui(tasks, files):
|
|
| 139 |
tasks_html = build_tasks_html(tasks)
|
| 140 |
return tasks, files, tasks_html
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
def main():
|
| 143 |
# Start the background task processor.
|
| 144 |
processor_thread = threading.Thread(target=background_task_processor, daemon=True)
|
|
@@ -147,9 +151,9 @@ def main():
|
|
| 147 |
with gr.Blocks() as demo:
|
| 148 |
gr.Markdown("# Advanced Multi-Task Report & Diagram Generator")
|
| 149 |
gr.Markdown(
|
| 150 |
-
"Enter your task command below. For example, you can type
|
| 151 |
"<i>generate a report on unemployment in the United States in 2024</i><br>"
|
| 152 |
-
"The system will automatically detect
|
| 153 |
"Multiple tasks run concurrently, and you can watch their progress and view details when complete."
|
| 154 |
)
|
| 155 |
|
|
@@ -159,6 +163,13 @@ def main():
|
|
| 159 |
with gr.Column(scale=2):
|
| 160 |
submit_btn = gr.Button("Submit")
|
| 161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
gr.Markdown("### Task List")
|
| 163 |
tasks_html_output = gr.HTML(label="Tasks Overview")
|
| 164 |
|
|
@@ -169,14 +180,26 @@ def main():
|
|
| 169 |
tasks_state = gr.State([])
|
| 170 |
files_state = gr.State([])
|
| 171 |
|
|
|
|
|
|
|
|
|
|
| 172 |
# When the user submits a task, update the states.
|
| 173 |
submit_btn.click(
|
| 174 |
submit_task,
|
| 175 |
inputs=[command_input, tasks_state],
|
| 176 |
outputs=[tasks_state, files_state, command_input]
|
| 177 |
)
|
| 178 |
-
#
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
| 182 |
|
|
|
|
| 82 |
with bucket_lock:
|
| 83 |
task_bucket.append(new_task)
|
| 84 |
current_tasks.append(new_task)
|
| 85 |
+
return current_tasks, generated_files, "" # Clear the input after submission.
|
| 86 |
|
| 87 |
def build_tasks_html(tasks):
|
| 88 |
"""
|
|
|
|
| 96 |
th, td {border: 1px solid #ddd; padding: 8px; text-align: left; font-size: 14px;}
|
| 97 |
th {background-color: #f2f2f2;}
|
| 98 |
.Complete {background-color: #d4edda;}
|
| 99 |
+
.In\\ Progress {background-color: #fff3cd;}
|
| 100 |
.Pending {background-color: #f8d7da;}
|
| 101 |
</style>
|
| 102 |
<table>
|
|
|
|
| 139 |
tasks_html = build_tasks_html(tasks)
|
| 140 |
return tasks, files, tasks_html
|
| 141 |
|
| 142 |
+
def set_sample_command(sample_command):
|
| 143 |
+
"""Returns the sample command to be populated in the textbox."""
|
| 144 |
+
return sample_command
|
| 145 |
+
|
| 146 |
def main():
|
| 147 |
# Start the background task processor.
|
| 148 |
processor_thread = threading.Thread(target=background_task_processor, daemon=True)
|
|
|
|
| 151 |
with gr.Blocks() as demo:
|
| 152 |
gr.Markdown("# Advanced Multi-Task Report & Diagram Generator")
|
| 153 |
gr.Markdown(
|
| 154 |
+
"Enter your task command below or click one of the sample commands. For example, you can type or select:<br>"
|
| 155 |
"<i>generate a report on unemployment in the United States in 2024</i><br>"
|
| 156 |
+
"The system will automatically detect your request and generate a PDF report (unless a different format is specified).<br>"
|
| 157 |
"Multiple tasks run concurrently, and you can watch their progress and view details when complete."
|
| 158 |
)
|
| 159 |
|
|
|
|
| 163 |
with gr.Column(scale=2):
|
| 164 |
submit_btn = gr.Button("Submit")
|
| 165 |
|
| 166 |
+
# Row of sample command buttons.
|
| 167 |
+
gr.Markdown("#### Sample Commands")
|
| 168 |
+
with gr.Row():
|
| 169 |
+
sample1 = gr.Button("Report on unemployment in the US 2024")
|
| 170 |
+
sample2 = gr.Button("Generate diagram of sales data")
|
| 171 |
+
sample3 = gr.Button("Generate csv report of user activity")
|
| 172 |
+
|
| 173 |
gr.Markdown("### Task List")
|
| 174 |
tasks_html_output = gr.HTML(label="Tasks Overview")
|
| 175 |
|
|
|
|
| 180 |
tasks_state = gr.State([])
|
| 181 |
files_state = gr.State([])
|
| 182 |
|
| 183 |
+
with gr.Row():
|
| 184 |
+
refresh_btn = gr.Button("Refresh Task List")
|
| 185 |
+
|
| 186 |
# When the user submits a task, update the states.
|
| 187 |
submit_btn.click(
|
| 188 |
submit_task,
|
| 189 |
inputs=[command_input, tasks_state],
|
| 190 |
outputs=[tasks_state, files_state, command_input]
|
| 191 |
)
|
| 192 |
+
# Sample buttons fill the command textbox.
|
| 193 |
+
sample1.click(set_sample_command, inputs=[], outputs=command_input, _js="() => 'generate a report on unemployment in the United States in 2024'")
|
| 194 |
+
sample2.click(set_sample_command, inputs=[], outputs=command_input, _js="() => 'generate diagram of sales data'")
|
| 195 |
+
sample3.click(set_sample_command, inputs=[], outputs=command_input, _js="() => 'generate csv report of user activity'")
|
| 196 |
+
|
| 197 |
+
# Refresh the task list when the refresh button is clicked.
|
| 198 |
+
refresh_btn.click(
|
| 199 |
+
refresh_ui,
|
| 200 |
+
inputs=[tasks_state, files_state],
|
| 201 |
+
outputs=[tasks_state, files_state, tasks_html_output]
|
| 202 |
+
)
|
| 203 |
|
| 204 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
| 205 |
|