File size: 1,053 Bytes
68f6561
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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)