Update app.py
Browse files
app.py
CHANGED
|
@@ -66,9 +66,10 @@ def submit_task(command, current_tasks):
|
|
| 66 |
"""
|
| 67 |
Called when the user clicks Submit.
|
| 68 |
Creates a new task with a timestamp and adds it to the task bucket.
|
|
|
|
| 69 |
"""
|
| 70 |
if command.strip() == "":
|
| 71 |
-
return current_tasks, generated_files,
|
| 72 |
new_task = {
|
| 73 |
"command": command,
|
| 74 |
"submitted_at": datetime.now().strftime("%H:%M:%S"),
|
|
@@ -82,7 +83,8 @@ def submit_task(command, current_tasks):
|
|
| 82 |
with bucket_lock:
|
| 83 |
task_bucket.append(new_task)
|
| 84 |
current_tasks.append(new_task)
|
| 85 |
-
|
|
|
|
| 86 |
|
| 87 |
def build_tasks_html(tasks):
|
| 88 |
"""
|
|
@@ -147,10 +149,10 @@ 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 or click one of the sample commands. For example
|
| 151 |
"<i>generate a report on unemployment in the United States in 2024</i><br>"
|
| 152 |
"The system will automatically detect your request and generate a PDF report (unless a different format is specified).<br>"
|
| 153 |
-
"Multiple tasks run concurrently, and you can watch their progress
|
| 154 |
)
|
| 155 |
|
| 156 |
with gr.Row():
|
|
@@ -159,7 +161,6 @@ def main():
|
|
| 159 |
with gr.Column(scale=2):
|
| 160 |
submit_btn = gr.Button("Submit")
|
| 161 |
|
| 162 |
-
# Row of sample command buttons.
|
| 163 |
gr.Markdown("#### Sample Commands")
|
| 164 |
with gr.Row():
|
| 165 |
sample1 = gr.Button("Report on US Unemployment 2024")
|
|
@@ -185,17 +186,23 @@ def main():
|
|
| 185 |
inputs=[command_input, tasks_state],
|
| 186 |
outputs=[tasks_state, files_state, command_input]
|
| 187 |
)
|
| 188 |
-
# Sample buttons fill the command textbox
|
| 189 |
sample1.click(lambda: "generate a report on unemployment in the United States in 2024", None, command_input)
|
| 190 |
sample2.click(lambda: "generate diagram of sales data", None, command_input)
|
| 191 |
sample3.click(lambda: "generate csv report of user activity", None, command_input)
|
| 192 |
|
| 193 |
-
#
|
| 194 |
refresh_btn.click(
|
| 195 |
refresh_ui,
|
| 196 |
inputs=[tasks_state, files_state],
|
| 197 |
outputs=[tasks_state, files_state, tasks_html_output]
|
| 198 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
| 201 |
|
|
|
|
| 66 |
"""
|
| 67 |
Called when the user clicks Submit.
|
| 68 |
Creates a new task with a timestamp and adds it to the task bucket.
|
| 69 |
+
Unlike before, the command textbox is NOT cleared after submission.
|
| 70 |
"""
|
| 71 |
if command.strip() == "":
|
| 72 |
+
return current_tasks, generated_files, command
|
| 73 |
new_task = {
|
| 74 |
"command": command,
|
| 75 |
"submitted_at": datetime.now().strftime("%H:%M:%S"),
|
|
|
|
| 83 |
with bucket_lock:
|
| 84 |
task_bucket.append(new_task)
|
| 85 |
current_tasks.append(new_task)
|
| 86 |
+
# Return the same command so it remains visible.
|
| 87 |
+
return current_tasks, generated_files, command
|
| 88 |
|
| 89 |
def build_tasks_html(tasks):
|
| 90 |
"""
|
|
|
|
| 149 |
with gr.Blocks() as demo:
|
| 150 |
gr.Markdown("# Advanced Multi-Task Report & Diagram Generator")
|
| 151 |
gr.Markdown(
|
| 152 |
+
"Enter your task command below or click one of the sample commands. For example:<br>"
|
| 153 |
"<i>generate a report on unemployment in the United States in 2024</i><br>"
|
| 154 |
"The system will automatically detect your request and generate a PDF report (unless a different format is specified).<br>"
|
| 155 |
+
"Multiple tasks run concurrently, and you can watch their progress below."
|
| 156 |
)
|
| 157 |
|
| 158 |
with gr.Row():
|
|
|
|
| 161 |
with gr.Column(scale=2):
|
| 162 |
submit_btn = gr.Button("Submit")
|
| 163 |
|
|
|
|
| 164 |
gr.Markdown("#### Sample Commands")
|
| 165 |
with gr.Row():
|
| 166 |
sample1 = gr.Button("Report on US Unemployment 2024")
|
|
|
|
| 186 |
inputs=[command_input, tasks_state],
|
| 187 |
outputs=[tasks_state, files_state, command_input]
|
| 188 |
)
|
| 189 |
+
# Sample buttons fill the command textbox.
|
| 190 |
sample1.click(lambda: "generate a report on unemployment in the United States in 2024", None, command_input)
|
| 191 |
sample2.click(lambda: "generate diagram of sales data", None, command_input)
|
| 192 |
sample3.click(lambda: "generate csv report of user activity", None, command_input)
|
| 193 |
|
| 194 |
+
# Manual refresh button.
|
| 195 |
refresh_btn.click(
|
| 196 |
refresh_ui,
|
| 197 |
inputs=[tasks_state, files_state],
|
| 198 |
outputs=[tasks_state, files_state, tasks_html_output]
|
| 199 |
)
|
| 200 |
+
# Also auto-refresh the task list every 5 seconds.
|
| 201 |
+
demo.load(
|
| 202 |
+
refresh_ui,
|
| 203 |
+
inputs=[tasks_state, files_state],
|
| 204 |
+
outputs=[tasks_state, files_state, tasks_html_output]
|
| 205 |
+
)
|
| 206 |
|
| 207 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
| 208 |
|