wlo / app.py
mysome's picture
Update app.py
789b255 verified
Raw
History Blame Contribute Delete
1.18 kB
import gradio as gr
import os
from wakeonlan import send_magic_packet
import socket
# ุจูŠุงู†ุงุช ุฌู‡ุงุฒูƒ
MAC = "dc:4a:3e:9a:eb:87"
PUBLIC_IP = "154.254.93.204"
def wake_pc():
try:
send_magic_packet(MAC)
return f"โœ… Wake-on-LAN signal sent to {MAC} ({PUBLIC_IP})"
except Exception as e:
return f"โŒ Error: {str(e)}"
def ping_pc():
try:
response = os.system(f"ping -c 1 {PUBLIC_IP}" if os.name != "nt" else f"ping -n 1 {PUBLIC_IP}")
if response == 0:
return f"โœ… {PUBLIC_IP} is Online"
else:
return f"โš ๏ธ {PUBLIC_IP} is Offline"
except Exception as e:
return f"โŒ Error: {str(e)}"
# ูˆุงุฌู‡ุฉ Gradio
with gr.Blocks() as demo:
gr.Markdown("## ๐ŸŒ Remote PC Controller (Wake-on-LAN + Ping)")
with gr.Row():
wake_btn = gr.Button("๐Ÿ”Œ Wake PC")
ping_btn = gr.Button("๐Ÿ“ก Ping PC")
output = gr.Textbox(label="Result")
wake_btn.click(fn=wake_pc, inputs=None, outputs=output)
ping_btn.click(fn=ping_pc, inputs=None, outputs=output)
# ุชุดุบูŠู„ Gradio
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=7860)