lzghades commited on
Commit
b92b4dc
1 Parent(s): 8fccbdd
Files changed (1) hide show
  1. app.py +25 -11
app.py CHANGED
@@ -4,11 +4,22 @@
4
  import uuid
5
  import time
6
  import os
 
 
7
  import requests
8
  import gradio as gr
9
  import simplejson as json
10
  import oss2
11
 
 
 
 
 
 
 
 
 
 
12
  CSS = '.gradio-container a {color:#b7adf4 !important}'
13
  HEADERS = {'app-key': os.environ['a3'], 'origin': os.environ['a4'], 'referer': os.environ['a4']}
14
 
@@ -21,7 +32,8 @@ def login(loginId, password):
21
  resp = requests.post(os.environ['a5'], data=data, headers=HEADERS, cookies=cookies)
22
  if resp.status_code == 200:
23
  return resp.json()['data']['token']
24
- except Exception:
 
25
  raise gr.Error('登录错误,请确认你的720yun账号是否正确')
26
 
27
 
@@ -29,14 +41,14 @@ 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
@@ -51,8 +63,9 @@ def create_panorama(prompt, negative_prompt):
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
 
@@ -115,7 +128,8 @@ def upload(token, file_id, file_url):
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
 
@@ -153,7 +167,7 @@ with gr.Blocks(css=CSS) as demo:
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)
158
 
159
- demo.queue(concurrency_count=3).launch()
 
4
  import uuid
5
  import time
6
  import os
7
+ import logging
8
+ import logging.handlers
9
  import requests
10
  import gradio as gr
11
  import simplejson as json
12
  import oss2
13
 
14
+ LOGGER = logging.getLogger('skybox')
15
+ HANDLER = logging.handlers.RotatingFileHandler(
16
+ './logs/skybox.log', mode='a', maxBytes=20 * 1000 * 1000, backupCount=5, encoding='utf-8')
17
+ FORMATTER = logging.Formatter('%(asctime)s - %(funcName)s - %(lineno)d - %(levelname)s - %(message)s')
18
+ HANDLER.setFormatter(FORMATTER)
19
+ LOGGER.propagate = 0
20
+ LOGGER.addHandler(HANDLER)
21
+ LOGGER.setLevel(logging.DEBUG)
22
+
23
  CSS = '.gradio-container a {color:#b7adf4 !important}'
24
  HEADERS = {'app-key': os.environ['a3'], 'origin': os.environ['a4'], 'referer': os.environ['a4']}
25
 
 
32
  resp = requests.post(os.environ['a5'], data=data, headers=HEADERS, cookies=cookies)
33
  if resp.status_code == 200:
34
  return resp.json()['data']['token']
35
+ except Exception as e:
36
+ LOGGER.error(e)
37
  raise gr.Error('登录错误,请确认你的720yun账号是否正确')
38
 
39
 
 
41
  try:
42
  data = {
43
  'api_key': os.environ['a2'],
44
+ 'generator': 'stable-skybox',
45
+ 'prompt': prompt.strip()[0:598],
46
+ 'negative_text': negative_prompt.strip()[0:398]
47
  }
48
  resp = requests.post(os.environ['a1'], data=data)
49
+ LOGGER.info(resp.text)
50
  if resp.status_code == 200:
51
+ time.sleep(15)
52
  request_id = resp.json()['request']['id']
53
  flag = True
54
  countdown = 50
 
63
  if progress_data['progress'] == 100 and progress_data['status'] == 'complete':
64
  flag = False
65
  return request_id, progress_data['file_url']
66
+ time.sleep(1)
67
+ except Exception as e:
68
+ LOGGER.error(e)
69
  raise gr.Error('AI老师罢工了,请稍后重试')
70
 
71
 
 
128
  resp = requests.post(os.environ['a8'], data=data, headers=HEADERS)
129
  if resp.status_code == 200:
130
  return resp.json()['data']['tid']
131
+ except Exception as e:
132
+ LOGGER.error(e)
133
  raise gr.Error('AI老师罢工了,请稍后重试')
134
 
135
 
 
167
  with gr.Row():
168
  out = gr.Textbox(label='输出')
169
 
170
+ btn = gr.Button('运行')
171
  btn.click(fn=main, inputs=[login_id, password, prompt, negative_prompt, session], outputs=out, show_progress=True)
172
 
173
+ demo.queue(concurrency_count=8).launch()