Update app.py
Browse files
app.py
CHANGED
|
@@ -8,16 +8,22 @@ import gradio as gr
|
|
| 8 |
# Tor IP rotation functions
|
| 9 |
# -------------------------------
|
| 10 |
def renew_tor_ip():
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 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
|