Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import json
|
3 |
+
import time
|
4 |
+
|
5 |
+
status_file = "status.json"
|
6 |
+
command_file = "command.json"
|
7 |
+
|
8 |
+
# Initialize storage files
|
9 |
+
with open(status_file, "w") as f:
|
10 |
+
json.dump({}, f)
|
11 |
+
with open(command_file, "w") as f:
|
12 |
+
json.dump({}, f)
|
13 |
+
|
14 |
+
# Register PC as online
|
15 |
+
def register_pc(name, password):
|
16 |
+
with open(status_file, "r") as f:
|
17 |
+
status = json.load(f)
|
18 |
+
status[name] = {"password": password, "timestamp": time.time()}
|
19 |
+
with open(status_file, "w") as f:
|
20 |
+
json.dump(status, f)
|
21 |
+
return f"PC '{name}' registered as online."
|
22 |
+
|
23 |
+
# Check if PC is online
|
24 |
+
def check_pc(name):
|
25 |
+
with open(status_file, "r") as f:
|
26 |
+
status = json.load(f)
|
27 |
+
if name in status and time.time() - status[name]["timestamp"] < 60:
|
28 |
+
return "Online"
|
29 |
+
return "Offline"
|
30 |
+
|
31 |
+
# Send command
|
32 |
+
def send_command(name, password, command):
|
33 |
+
with open(status_file, "r") as f:
|
34 |
+
status = json.load(f)
|
35 |
+
if name in status and status[name]["password"] == password:
|
36 |
+
with open(command_file, "w") as f:
|
37 |
+
json.dump({"command": command}, f)
|
38 |
+
return f"Command '{command}' sent to {name}."
|
39 |
+
return "Authentication failed."
|
40 |
+
|
41 |
+
# Get command (PC side)
|
42 |
+
def get_command():
|
43 |
+
with open(command_file, "r") as f:
|
44 |
+
cmd_data = json.load(f)
|
45 |
+
return cmd_data.get("command", "")
|
46 |
+
|
47 |
+
# Gradio UI
|
48 |
+
with gr.Blocks() as ui:
|
49 |
+
with gr.Row():
|
50 |
+
name_input = gr.Textbox(label="PC Name")
|
51 |
+
pass_input = gr.Textbox(label="Password", type="password")
|
52 |
+
check_btn = gr.Button("Check Online Status")
|
53 |
+
check_output = gr.Textbox(label="Status")
|
54 |
+
check_btn.click(check_pc, inputs=name_input, outputs=check_output)
|
55 |
+
|
56 |
+
with gr.Row():
|
57 |
+
cmd_input = gr.Textbox(label="Command")
|
58 |
+
send_btn = gr.Button("Send Command")
|
59 |
+
send_output = gr.Textbox(label="Response")
|
60 |
+
send_btn.click(send_command, inputs=[name_input, pass_input, cmd_input], outputs=send_output)
|
61 |
+
|
62 |
+
ui.launch(share=True)
|