triflix commited on
Commit
d5a6f8a
·
verified ·
1 Parent(s): 656a9ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -8,16 +8,22 @@ import gradio as gr
8
  # Tor IP rotation functions
9
  # -------------------------------
10
  def renew_tor_ip():
11
- with Controller.from_port(port=9051) as controller:
12
- controller.authenticate()
13
- controller.signal(Signal.NEWNYM)
14
- time.sleep(5) # Give Tor time to switch
 
 
 
15
 
16
  def request_via_tor(url):
17
  proxies = {"http": "socks5h://127.0.0.1:9050",
18
  "https": "socks5h://127.0.0.1:9050"}
19
- response = requests.get(url, proxies=proxies, timeout=30)
20
- return response.json()
 
 
 
21
 
22
  # -------------------------------
23
  # Gradio interface
 
8
  # Tor IP rotation functions
9
  # -------------------------------
10
  def renew_tor_ip():
11
+ try:
12
+ with Controller.from_port(port=9051) as controller:
13
+ controller.authenticate()
14
+ controller.signal(Signal.NEWNYM)
15
+ time.sleep(5) # Give Tor time to switch
16
+ except Exception as e:
17
+ return f"Error renewing Tor IP: {e}"
18
 
19
  def request_via_tor(url):
20
  proxies = {"http": "socks5h://127.0.0.1:9050",
21
  "https": "socks5h://127.0.0.1:9050"}
22
+ try:
23
+ response = requests.get(url, proxies=proxies, timeout=30)
24
+ return response.json()
25
+ except Exception as e:
26
+ return {"error": str(e)}
27
 
28
  # -------------------------------
29
  # Gradio interface