Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,28 @@
|
|
| 1 |
-
import os
|
|
|
|
|
|
|
| 2 |
|
|
|
|
|
|
|
|
|
|
| 3 |
HCAPTCHA_SECRET = os.environ.get("HCAPTCHA_SECRET")
|
| 4 |
-
HCAPTCHA_SITEKEY = os.environ.get("HCAPTCHA_SITEKEY")
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 33 |
-
token_box.change(fn=verify_hcaptcha, inputs=token_box, outputs=output)
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
| 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)
|