|
|
|
|
|
from flask import Flask, redirect |
|
import requests |
|
import os |
|
import random |
|
from flask import Flask, redirect |
|
import requests |
|
import os |
|
import subprocess |
|
ngrok_token3 = "2cZivBw4scg2NQLDwuHPrHSbvkl_43ZbqjNAg5LVnvWXnQX5m" |
|
edge3 = "edghts_2cZj7RmeYoekH1kwK6RtexSkm0Z" |
|
command_ngrok = f"ngrok tunnel --label edge={edge3} --authtoken={ngrok_token3} --region=ap http://localhost:5006" |
|
|
|
app = Flask(__name__) |
|
|
|
def check_website_availability(url): |
|
try: |
|
response = requests.get(url) |
|
|
|
return response.status_code // 100 == 2 |
|
except requests.ConnectionError: |
|
return False |
|
|
|
@app.route('/') |
|
def redirect_to_website(): |
|
url = os.getenv('OPENI_GRADIO_URL') |
|
server1 = 'https://mlunotebook.openi.org.cn' |
|
server2 = 'http://cloudbrain1notebook.openi.org.cn' |
|
|
|
url1 = server1 + url + "/" |
|
url2 = server2 + url + "/" |
|
|
|
|
|
options = [url1, f"{url1}sd2/", f"{url1}sd3/", f"{url1}sd4/"] |
|
selected_url = random.choices(options, weights=[0.25, 0.25, 0.25, 0.25])[0] |
|
|
|
options2 = [url2, f"{url2}sd2/", f"{url2}sd3/", f"{url2}sd4/"] |
|
selected_url2 = random.choices(options2, weights=[0.25, 0.25, 0.25, 0.25])[0] |
|
|
|
if check_website_availability(url1): |
|
return redirect(selected_url) |
|
else: |
|
|
|
return redirect(selected_url2) |
|
|
|
if __name__ == '__main__': |
|
app.run(debug=False, port=5006) |
|
|