Vibow commited on
Commit
4394363
Β·
verified Β·
1 Parent(s): 91358f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -26
app.py CHANGED
@@ -1,35 +1,28 @@
1
- import os, requests, gradio as gr
 
 
2
 
 
 
 
3
  HCAPTCHA_SECRET = os.environ.get("HCAPTCHA_SECRET")
4
- HCAPTCHA_SITEKEY = os.environ.get("HCAPTCHA_SITEKEY")
5
 
6
- def verify_hcaptcha(token: str):
 
 
 
 
 
 
 
7
  if not token:
8
- return "❌ No token received."
 
9
  url = "https://hcaptcha.com/siteverify"
10
  data = {"secret": HCAPTCHA_SECRET, "response": token}
11
  result = requests.post(url, data=data).json()
12
- return f"πŸ”‘ Token: {token}<br>βœ… Result: {result}"
13
-
14
- with gr.Blocks() as demo:
15
- token_box = gr.Textbox(label="Debug Token", visible=True, elem_id="hcaptcha-token")
16
- output = gr.HTML("<i>⚑ Waiting for captcha...</i>")
17
-
18
- gr.HTML(f"""
19
- <script src="https://hcaptcha.com/1/api.js" async defer></script>
20
- <div class="h-captcha" data-sitekey="{HCAPTCHA_SITEKEY}" data-callback="setToken"></div>
21
- <script>
22
- function setToken(token) {{
23
- let textbox = document.getElementById("hcaptcha-token");
24
- if (textbox) {{
25
- textbox.value = token;
26
- textbox.dispatchEvent(new Event("input", {{ bubbles: true }}));
27
- }}
28
- }}
29
- </script>
30
- """)
31
 
32
- # whenever token_box changes, auto verify
33
- token_box.change(fn=verify_hcaptcha, inputs=token_box, outputs=output)
34
 
35
- demo.launch()
 
 
1
+ import os
2
+ import requests
3
+ from flask import Flask, request, jsonify, send_file
4
 
5
+ app = Flask(__name__)
6
+
7
+ # πŸ”‘ Ambil secret key dari Hugging Face Secrets
8
  HCAPTCHA_SECRET = os.environ.get("HCAPTCHA_SECRET")
 
9
 
10
+ @app.route("/")
11
+ def index():
12
+ # Serve index.html langsung dari root
13
+ return send_file("index.html")
14
+
15
+ @app.route("/verify", methods=["POST"])
16
+ def verify():
17
+ token = request.form.get("token")
18
  if not token:
19
+ return jsonify({"success": False, "error": "❌ No token received"}), 400
20
+
21
  url = "https://hcaptcha.com/siteverify"
22
  data = {"secret": HCAPTCHA_SECRET, "response": token}
23
  result = requests.post(url, data=data).json()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
+ return jsonify(result)
 
26
 
27
+ if __name__ == "__main__":
28
+ app.run(host="0.0.0.0", port=7860)