greendra commited on
Commit
30c4efd
·
1 Parent(s): 418b087

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -25
app.py CHANGED
@@ -22,35 +22,45 @@ sd_decode = os.environ.get('sd_decode')
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
 
22
 
23
  def freeimagehost(prompt, img, seed):
24
  try:
25
+ # Replace with the path to your proxy.txt file
26
+ proxy_file = "proxies.txt"
 
 
 
 
 
 
 
 
 
 
27
 
28
+ # Read the proxies from the file and store them in a list
29
+ with open(proxy_file, "r") as f:
30
+ proxies = f.read().splitlines()
31
+
32
+ # Read the image file and encode it as base64
33
  buffered = BytesIO()
34
+ img.save(buffered, format="PNG")
35
+ encoded_image = base64.b64encode(buffered.getvalue()).decode("utf-8")
36
+
37
+ uploaded = False
38
+ # Iterate over the proxies and make a post request with each one
39
+ for proxy in proxies:
40
+ if not uploaded:
41
+ try:
42
+ # Create a payload with the base64-encoded image and API key
43
+ key = "6d207e02198a847aa98d0a2a901485a5"
44
+ payload = {"key": key, "image": encoded_image, "format": "json", "expiration": "3600"}
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