update
Browse files
app.py
CHANGED
@@ -13,31 +13,47 @@ HEADERS = {'app-key': os.environ['a3'], 'origin': os.environ['a4'], 'referer': o
|
|
13 |
|
14 |
|
15 |
def login(loginId, password):
|
16 |
-
|
17 |
-
|
|
|
18 |
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
24 |
|
25 |
|
26 |
def create_panorama(prompt, negative_prompt):
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
|
43 |
def upload(token, file_id, file_url):
|
@@ -54,81 +70,88 @@ def upload(token, file_id, file_url):
|
|
54 |
'action': 1
|
55 |
}]
|
56 |
HEADERS['app-authorization'] = token
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
flag = True
|
80 |
-
while flag:
|
81 |
-
pano_ids = [pano['id'] for pano in requests.get(os.environ["a7"], headers=HEADERS).json()['data']]
|
82 |
-
if pano_id not in pano_ids:
|
83 |
-
flag = False
|
84 |
-
break
|
85 |
-
time.sleep(1)
|
86 |
-
data = {
|
87 |
-
'name': f'AI全景作品-{now}',
|
88 |
-
'materials': json.dumps([{
|
89 |
-
'type': 1,
|
90 |
-
'id': pano_id
|
91 |
-
}]),
|
92 |
-
'templateId': 2,
|
93 |
-
'publishPlatform': 1,
|
94 |
-
'keywords': 'AI全景',
|
95 |
-
'source': 99
|
96 |
-
}
|
97 |
-
resp = requests.post(os.environ['a8'], data=data, headers=HEADERS)
|
98 |
if resp.status_code == 200:
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
|
101 |
|
102 |
def main(loginId, password, prompt, negative_prompt, state, progress=gr.Progress()):
|
103 |
-
|
104 |
-
|
105 |
-
|
|
|
106 |
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
|
|
110 |
|
111 |
|
112 |
with gr.Blocks(css=CSS) as demo:
|
113 |
session = gr.State({})
|
114 |
|
115 |
gr.Markdown("""
|
116 |
-
#
|
117 |
-
1.
|
118 |
-
2.
|
119 |
-
3.
|
120 |
""")
|
121 |
with gr.Row():
|
122 |
with gr.Column():
|
123 |
-
login_id = gr.Textbox(label='
|
124 |
with gr.Column():
|
125 |
-
password = gr.Textbox(label='
|
126 |
with gr.Row():
|
127 |
-
prompt = gr.Textbox(label='
|
128 |
with gr.Row():
|
129 |
-
negative_prompt = gr.Textbox(label='
|
130 |
with gr.Row():
|
131 |
-
out = gr.Textbox(label='
|
132 |
|
133 |
btn = gr.Button('Run')
|
134 |
btn.click(fn=main, inputs=[login_id, password, prompt, negative_prompt, session], outputs=out, show_progress=True)
|
|
|
13 |
|
14 |
|
15 |
def login(loginId, password):
|
16 |
+
try:
|
17 |
+
data = {'loginId': loginId, 'password': password}
|
18 |
+
cookies = {'720yun_v8_session': os.environ['a3']}
|
19 |
|
20 |
+
resp = requests.post(os.environ['a5'], data=data, headers=HEADERS, cookies=cookies)
|
21 |
|
22 |
+
if resp.status_code == 200:
|
23 |
+
return resp.json()['data']['token']
|
24 |
+
except Exception:
|
25 |
+
raise gr.Error('登录错误,请确认你的720yun账号是否正确')
|
26 |
|
27 |
|
28 |
def create_panorama(prompt, negative_prompt):
|
29 |
+
try:
|
30 |
+
data = {
|
31 |
+
'api_key': os.environ['a2'],
|
32 |
+
'generator': 'stable-skybox-trt',
|
33 |
+
'prompt': prompt[0:598],
|
34 |
+
'negative_text': negative_prompt[0:398]
|
35 |
+
}
|
36 |
+
resp = requests.post(os.environ['a1'], data=data)
|
37 |
+
print(resp.text)
|
38 |
+
if resp.status_code == 200:
|
39 |
+
time.sleep(20)
|
40 |
+
request_id = resp.json()['request']['id']
|
41 |
+
flag = True
|
42 |
+
countdown = 50
|
43 |
+
while flag:
|
44 |
+
countdown -= 1
|
45 |
+
if countdown <= 0:
|
46 |
+
raise gr.Error('AI老师罢工了,请稍后重试')
|
47 |
+
|
48 |
+
resp = requests.get(f'{os.environ["a1"]}/{request_id}?api_key={os.environ["a2"]}')
|
49 |
+
if resp.status_code == 200:
|
50 |
+
progress_data = resp.json()['request']
|
51 |
+
if progress_data['progress'] == 100 and progress_data['status'] == 'complete':
|
52 |
+
flag = False
|
53 |
+
return request_id, progress_data['file_url']
|
54 |
+
time.sleep(0.5)
|
55 |
+
except Exception:
|
56 |
+
raise gr.Error('AI老师罢工了,请稍后重试')
|
57 |
|
58 |
|
59 |
def upload(token, file_id, file_url):
|
|
|
70 |
'action': 1
|
71 |
}]
|
72 |
HEADERS['app-authorization'] = token
|
73 |
+
|
74 |
+
try:
|
75 |
+
resp = requests.post(os.environ['a6'], data={'panos': json.dumps(data)}, headers=HEADERS)
|
76 |
+
if resp.status_code == 200:
|
77 |
+
resp_data = resp.json()['data'][0]
|
78 |
+
access_key_id = resp_data['accessKeyId']
|
79 |
+
security_token = resp_data['securityToken']
|
80 |
+
accessKey_secret = resp_data['accessKeySecret']
|
81 |
+
bucket_name = resp_data['bucketName']
|
82 |
+
path = resp_data['path'][1:]
|
83 |
+
endpoint = resp_data['endpointO']
|
84 |
+
pano_id = resp_data['panoId']
|
85 |
+
task_id = resp_data['taskId']
|
86 |
+
expired = resp_data['expired']
|
87 |
+
|
88 |
+
auth = oss2.StsAuth(access_key_id, accessKey_secret, security_token)
|
89 |
+
bucket = oss2.Bucket(auth, endpoint, bucket_name)
|
90 |
+
|
91 |
+
input_stream = requests.get(file_url)
|
92 |
+
result = bucket.put_object(f'{path}/{pano_id}.jpg', input_stream)
|
93 |
+
if result.status == 200:
|
94 |
+
resp = requests.post(f'{os.environ["a6"]}/{task_id}', data={'status': 3, 'expired': expired}, headers=HEADERS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
if resp.status_code == 200:
|
96 |
+
time.sleep(5)
|
97 |
+
flag = True
|
98 |
+
while flag:
|
99 |
+
pano_ids = [pano['id'] for pano in requests.get(os.environ["a7"], headers=HEADERS).json()['data']]
|
100 |
+
if pano_id not in pano_ids:
|
101 |
+
flag = False
|
102 |
+
break
|
103 |
+
time.sleep(0.5)
|
104 |
+
data = {
|
105 |
+
'name': f'AI全景作品-{now}',
|
106 |
+
'materials': json.dumps([{
|
107 |
+
'type': 1,
|
108 |
+
'id': pano_id
|
109 |
+
}]),
|
110 |
+
'templateId': 2,
|
111 |
+
'publishPlatform': 1,
|
112 |
+
'keywords': 'AI全景',
|
113 |
+
'source': 99
|
114 |
+
}
|
115 |
+
resp = requests.post(os.environ['a8'], data=data, headers=HEADERS)
|
116 |
+
if resp.status_code == 200:
|
117 |
+
return resp.json()['data']['tid']
|
118 |
+
except Exception:
|
119 |
+
raise gr.Error('AI老师罢工了,请稍后重试')
|
120 |
|
121 |
|
122 |
def main(loginId, password, prompt, negative_prompt, state, progress=gr.Progress()):
|
123 |
+
try:
|
124 |
+
if 'token' not in state:
|
125 |
+
state['token'] = login(loginId, password)
|
126 |
+
token = state['token']
|
127 |
|
128 |
+
file_id, image = create_panorama(prompt, negative_prompt)
|
129 |
+
panorama_id = upload(token, file_id, image)
|
130 |
+
return f'https://www.720yun.com/vr/{panorama_id}'
|
131 |
+
except Exception as e:
|
132 |
+
return f'{e}'
|
133 |
|
134 |
|
135 |
with gr.Blocks(css=CSS) as demo:
|
136 |
session = gr.State({})
|
137 |
|
138 |
gr.Markdown("""
|
139 |
+
# 创造属于你自己的AI全景
|
140 |
+
1. 需要你的 **[720yun.com](https://www.720yun.com)** 账号.
|
141 |
+
2. 由 **[720yun.com](https://www.720yun.com)** 提供支持.
|
142 |
+
3. 描述例子: a beautiful matte painting, northernmost continent, a gigantic square fortress covered by blizzard, aerial view, epic composition, post apocalyptic, sci-fi, futuristic, fantasy, by Jan Urschel and Sergey Vasnev and Emmanuel Shiu and Michal Karcz, ornate, cinematic, cinematic lighting, light effect, epic, octane render, unreal engine, 4k hd wallpaper, trending on artstation and cgsociety
|
143 |
""")
|
144 |
with gr.Row():
|
145 |
with gr.Column():
|
146 |
+
login_id = gr.Textbox(label='账号: (必填)', placeholder='720yun 账号')
|
147 |
with gr.Column():
|
148 |
+
password = gr.Textbox(label='密码: (必填)', type='password', placeholder='720yun 密码')
|
149 |
with gr.Row():
|
150 |
+
prompt = gr.Textbox(label='描述: (必填)', lines=4, placeholder='请输入描述,最多600个字符')
|
151 |
with gr.Row():
|
152 |
+
negative_prompt = gr.Textbox(label='负面描述', lines=2, placeholder='请输入负面描述,最多400个字符')
|
153 |
with gr.Row():
|
154 |
+
out = gr.Textbox(label='输出')
|
155 |
|
156 |
btn = gr.Button('Run')
|
157 |
btn.click(fn=main, inputs=[login_id, password, prompt, negative_prompt, session], outputs=out, show_progress=True)
|