Download app.py from Dylan081/Wireguard: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/Dylan081/Wireguard/resolve/main/app.py
- Command line
-
hf download hf://spaces/Dylan081/Wireguard/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Dylan081/Wireguard/resolve/main/app.py
1.05 kB
| import requests | |
| import gradio as gr | |
| # Define your userspace proxy dictionaries | |
| PROXIES = { | |
| 'http': 'socks5h://127.0.0.1:1080', | |
| 'https': 'socks5h://127.0.0.1:1080' | |
| } | |
| def make_secure_api_call(target_url): | |
| try: | |
| # 'socks5h://' forces DNS queries to happen over the WireGuard peer rather than locally | |
| response = requests.get(target_url, proxies=PROXIES, timeout=10) | |
| # Safely handle JSON structures or fall back to plaintext presentation | |
| try: | |
| return response.json() | |
| except ValueError: | |
| return {"raw_response": response.text} | |
| except Exception as e: | |
| return {"error": str(e)} | |
| # Gradio Web Interface matching Hugging Face setup | |
| demo = gr.Interface( | |
| fn=make_secure_api_call, | |
| # Value points directly to the API endpoint instead of the main landing webpage | |
| inputs=gr.Textbox(value="https://ipify.org", label="Target Secure API URL"), | |
| outputs="json" | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch(server_name="0.0.0.0", server_port=7860) | |