Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -22,45 +22,35 @@ sd_decode = os.environ.get('sd_decode')
|
|
22 |
|
23 |
def freeimagehost(prompt, img, seed):
|
24 |
try:
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
|
33 |
buffered = BytesIO()
|
34 |
-
img.save(buffered, format="
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
# Make a post request with the proxy to upload the image
|
47 |
-
response = requests.post("https://freeimage.host/api/1/upload", data=payload, proxies={"http": proxy})
|
48 |
-
link = loglink = response.json()['image']['url']
|
49 |
-
link = '<a style="color:blue;" href="https://arinteli.com/app/?' + link + '+' + prompt + '+' + seed + '" target=”_blank”>'+ link +'</a>'
|
50 |
-
uploaded = True
|
51 |
-
|
52 |
-
except:
|
53 |
-
# If there's an error, assume the proxy is not working
|
54 |
-
print(f"Error uploading file with proxy {proxy}")
|
55 |
-
|
56 |
-
if not uploaded:
|
57 |
-
# If the image was not uploaded with any of the proxies, fallback to imagebb
|
58 |
return imagebb(prompt, img, seed)
|
59 |
-
|
60 |
-
except:
|
61 |
-
# If there's an error, fallback to imagebb
|
62 |
return imagebb(prompt, img, seed)
|
63 |
-
|
64 |
return link, loglink
|
65 |
|
66 |
bbtries = 0
|
|
|
22 |
|
23 |
def freeimagehost(prompt, img, seed):
|
24 |
try:
|
25 |
+
rp = RegisteredProviders()
|
26 |
+
rp.parse_providers()
|
27 |
+
# get one proxy
|
28 |
+
proxy = rp.get_random_proxy()
|
29 |
+
proxy = proxy.get_proxy()
|
30 |
+
# convert proxy to dictionary
|
31 |
+
proxy = proxy.split(':')
|
32 |
+
# convert list to dictionary
|
33 |
+
proxy = {'http': 'http://' + proxy[0] + ':' + proxy[1]}
|
34 |
+
except:
|
35 |
+
print("Error getting proxy")
|
36 |
+
proxy = {}
|
37 |
|
38 |
+
try:
|
39 |
buffered = BytesIO()
|
40 |
+
img.save(buffered, format="JPEG")
|
41 |
+
img_str = base64.b64encode(buffered.getvalue())
|
42 |
+
key = "6d207e02198a847aa98d0a2a901485a5"
|
43 |
+
payload = {'key': key, 'image': img_str, 'format': 'json', 'expiration': '3600'}
|
44 |
+
r = requests.post("https://freeimage.host/api/1/upload", data=payload, proxies=proxy)
|
45 |
+
r = json.loads(r.text)
|
46 |
+
try:
|
47 |
+
link = loglink = r['image']['url']
|
48 |
+
link = '<a style="color:blue;" href="https://arinteli.com/app/?' + link + '+' + prompt + '+' + seed + '" target=”_blank”>'+ link +'</a>'
|
49 |
+
except:
|
50 |
+
print(r)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
return imagebb(prompt, img, seed)
|
52 |
+
except:
|
|
|
|
|
53 |
return imagebb(prompt, img, seed)
|
|
|
54 |
return link, loglink
|
55 |
|
56 |
bbtries = 0
|