Spaces:
Paused
Paused
Upload folder using huggingface_hub
Browse files- frontend.py +18 -15
frontend.py
CHANGED
|
@@ -12,7 +12,7 @@ subprocess.Popen(["node", "dist/app.js"])
|
|
| 12 |
|
| 13 |
def get_status():
|
| 14 |
try:
|
| 15 |
-
r = requests.get(f"{NODE_URL}/health", timeout=
|
| 16 |
return r.json()
|
| 17 |
except:
|
| 18 |
return None
|
|
@@ -20,7 +20,7 @@ def get_status():
|
|
| 20 |
def update_ui():
|
| 21 |
status = get_status()
|
| 22 |
if not status:
|
| 23 |
-
return "Backend Offline", "Waiting for Node.js to start...", ""
|
| 24 |
|
| 25 |
msg = f"Status: {status.get('whatsappStatus', 'Unknown')}\nConnected: {status.get('connected')}\nReady: {status.get('ready')}"
|
| 26 |
|
|
@@ -45,8 +45,8 @@ def update_ui():
|
|
| 45 |
|
| 46 |
def trigger_init():
|
| 47 |
try:
|
| 48 |
-
requests.post(f"{NODE_URL}/init")
|
| 49 |
-
return "Initialization requested."
|
| 50 |
except Exception as e:
|
| 51 |
return f"Error: {str(e)}"
|
| 52 |
|
|
@@ -58,32 +58,35 @@ def send_poll(number, title, options):
|
|
| 58 |
except Exception as e:
|
| 59 |
return {"error": str(e)}
|
| 60 |
|
| 61 |
-
with gr.Blocks() as demo:
|
| 62 |
-
gr.Markdown("# π€ WPPConnect Control")
|
| 63 |
|
| 64 |
with gr.Row():
|
| 65 |
-
with gr.Column():
|
| 66 |
-
status_display = gr.
|
| 67 |
-
init_btn = gr.Button("π Start/Retry WhatsApp")
|
| 68 |
-
|
|
|
|
| 69 |
qr_display = gr.HTML(label="QR Code")
|
| 70 |
|
| 71 |
with gr.Tab("Send Poll"):
|
| 72 |
-
poll_num = gr.Textbox(label="Phone Number")
|
| 73 |
poll_title = gr.Textbox(label="Question")
|
| 74 |
poll_opts = gr.Textbox(label="Options (comma separated)")
|
| 75 |
poll_send = gr.Button("Send Poll")
|
| 76 |
poll_output = gr.JSON(label="Result")
|
| 77 |
|
| 78 |
-
log_display = gr.
|
| 79 |
-
refresh_btn = gr.Button("π Refresh UI")
|
| 80 |
|
| 81 |
init_btn.click(trigger_init, outputs=status_display)
|
| 82 |
refresh_btn.click(update_ui, outputs=[status_display, qr_display, log_display])
|
| 83 |
poll_send.click(send_poll, inputs=[poll_num, poll_title, poll_opts], outputs=poll_output)
|
| 84 |
|
| 85 |
-
#
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
if __name__ == "__main__":
|
| 89 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 12 |
|
| 13 |
def get_status():
|
| 14 |
try:
|
| 15 |
+
r = requests.get(f"{NODE_URL}/health", timeout=2)
|
| 16 |
return r.json()
|
| 17 |
except:
|
| 18 |
return None
|
|
|
|
| 20 |
def update_ui():
|
| 21 |
status = get_status()
|
| 22 |
if not status:
|
| 23 |
+
return "Backend Offline", "Waiting for Node.js to start...", "No logs available"
|
| 24 |
|
| 25 |
msg = f"Status: {status.get('whatsappStatus', 'Unknown')}\nConnected: {status.get('connected')}\nReady: {status.get('ready')}"
|
| 26 |
|
|
|
|
| 45 |
|
| 46 |
def trigger_init():
|
| 47 |
try:
|
| 48 |
+
r = requests.post(f"{NODE_URL}/init")
|
| 49 |
+
return "Initialization requested. Click 'Refresh' in a few seconds."
|
| 50 |
except Exception as e:
|
| 51 |
return f"Error: {str(e)}"
|
| 52 |
|
|
|
|
| 58 |
except Exception as e:
|
| 59 |
return {"error": str(e)}
|
| 60 |
|
| 61 |
+
with gr.Blocks(theme=gr.themes.Default()) as demo:
|
| 62 |
+
gr.Markdown("# π€ WPPConnect WhatsApp Control")
|
| 63 |
|
| 64 |
with gr.Row():
|
| 65 |
+
with gr.Column(scale=1):
|
| 66 |
+
status_display = gr.Textbox(label="System Status", lines=3)
|
| 67 |
+
init_btn = gr.Button("π Start/Retry WhatsApp", variant="primary")
|
| 68 |
+
refresh_btn = gr.Button("π Refresh Status/QR")
|
| 69 |
+
with gr.Column(scale=2):
|
| 70 |
qr_display = gr.HTML(label="QR Code")
|
| 71 |
|
| 72 |
with gr.Tab("Send Poll"):
|
| 73 |
+
poll_num = gr.Textbox(label="Phone Number (e.g. 5511999999999)")
|
| 74 |
poll_title = gr.Textbox(label="Question")
|
| 75 |
poll_opts = gr.Textbox(label="Options (comma separated)")
|
| 76 |
poll_send = gr.Button("Send Poll")
|
| 77 |
poll_output = gr.JSON(label="Result")
|
| 78 |
|
| 79 |
+
log_display = gr.Code(label="Internal Logs", language="markdown")
|
|
|
|
| 80 |
|
| 81 |
init_btn.click(trigger_init, outputs=status_display)
|
| 82 |
refresh_btn.click(update_ui, outputs=[status_display, qr_display, log_display])
|
| 83 |
poll_send.click(send_poll, inputs=[poll_num, poll_title, poll_opts], outputs=poll_output)
|
| 84 |
|
| 85 |
+
# Try to use every if Gradio version is new enough, otherwise fallback
|
| 86 |
+
try:
|
| 87 |
+
demo.load(update_ui, outputs=[status_display, qr_display, log_display], every=10)
|
| 88 |
+
except:
|
| 89 |
+
demo.load(update_ui, outputs=[status_display, qr_display, log_display])
|
| 90 |
|
| 91 |
if __name__ == "__main__":
|
| 92 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|