Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -51,13 +51,22 @@ def get_command():
|
|
| 51 |
cmd_data = json.load(f)
|
| 52 |
return cmd_data.get("command", "")
|
| 53 |
|
| 54 |
-
# Upload command output from PC
|
| 55 |
-
def upload_output(name, password, output):
|
| 56 |
with open(status_file, "r") as f:
|
| 57 |
status = json.load(f)
|
| 58 |
if name in status and status[name]["password"] == password:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
with open(output_file, "w") as f:
|
| 60 |
-
json.dump({"output":
|
| 61 |
return "Output uploaded successfully."
|
| 62 |
return "Authentication failed."
|
| 63 |
|
|
@@ -86,11 +95,19 @@ with gr.Blocks() as ui:
|
|
| 86 |
hidden_cmd_output = gr.Textbox(visible=False)
|
| 87 |
hidden_get_cmd_btn.click(get_command, inputs=[], outputs=hidden_cmd_output, api_name="/get_command")
|
| 88 |
|
|
|
|
| 89 |
output_input = gr.Textbox(label="Output", visible=False)
|
|
|
|
| 90 |
hidden_upload_btn = gr.Button("Hidden Upload Output", visible=False)
|
| 91 |
hidden_upload_output = gr.Textbox(visible=False)
|
| 92 |
-
hidden_upload_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
|
|
|
| 94 |
hidden_get_output_btn = gr.Button("Hidden Get Output", visible=False)
|
| 95 |
hidden_get_output = gr.Textbox(visible=False)
|
| 96 |
hidden_get_output_btn.click(get_output, inputs=[], outputs=hidden_get_output, api_name="/get_output")
|
|
|
|
| 51 |
cmd_data = json.load(f)
|
| 52 |
return cmd_data.get("command", "")
|
| 53 |
|
| 54 |
+
# Upload command output from PC with timestamps
|
| 55 |
+
def upload_output(name, password, output, sent_time):
|
| 56 |
with open(status_file, "r") as f:
|
| 57 |
status = json.load(f)
|
| 58 |
if name in status and status[name]["password"] == password:
|
| 59 |
+
received_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
| 60 |
+
# Format with time sent, a divider, then time received, another divider, and the actual output.
|
| 61 |
+
combined_output = (
|
| 62 |
+
f"Time Sent: {sent_time}\n"
|
| 63 |
+
"--------------------\n"
|
| 64 |
+
f"Time Received: {received_time}\n"
|
| 65 |
+
"--------------------\n"
|
| 66 |
+
f"{output}"
|
| 67 |
+
)
|
| 68 |
with open(output_file, "w") as f:
|
| 69 |
+
json.dump({"output": combined_output}, f)
|
| 70 |
return "Output uploaded successfully."
|
| 71 |
return "Authentication failed."
|
| 72 |
|
|
|
|
| 95 |
hidden_cmd_output = gr.Textbox(visible=False)
|
| 96 |
hidden_get_cmd_btn.click(get_command, inputs=[], outputs=hidden_cmd_output, api_name="/get_command")
|
| 97 |
|
| 98 |
+
# Hidden components for uploading output: include an extra textbox for sent_time
|
| 99 |
output_input = gr.Textbox(label="Output", visible=False)
|
| 100 |
+
sent_time_input = gr.Textbox(label="Sent Time", visible=False)
|
| 101 |
hidden_upload_btn = gr.Button("Hidden Upload Output", visible=False)
|
| 102 |
hidden_upload_output = gr.Textbox(visible=False)
|
| 103 |
+
hidden_upload_btn.click(
|
| 104 |
+
upload_output,
|
| 105 |
+
inputs=[name_input, pass_input, output_input, sent_time_input],
|
| 106 |
+
outputs=hidden_upload_output,
|
| 107 |
+
api_name="/upload_output"
|
| 108 |
+
)
|
| 109 |
|
| 110 |
+
# Hidden endpoint to retrieve output
|
| 111 |
hidden_get_output_btn = gr.Button("Hidden Get Output", visible=False)
|
| 112 |
hidden_get_output = gr.Textbox(visible=False)
|
| 113 |
hidden_get_output_btn.click(get_output, inputs=[], outputs=hidden_get_output, api_name="/get_output")
|