Spaces:
Runtime error
Runtime error
chenjian
commited on
Commit
·
5d4a3a1
1
Parent(s):
4cd14af
fix
Browse files- app.py +6 -0
- ernie_vilg/__pycache__/module.cpython-37.pyc +0 -0
- ernie_vilg/module.py +10 -1
app.py
CHANGED
|
@@ -1,14 +1,20 @@
|
|
| 1 |
import numpy as np
|
| 2 |
import gradio as gr
|
| 3 |
import paddlehub as hub
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
model = hub.Module(directory='ernie_vilg')
|
| 7 |
|
| 8 |
def inference(text_prompts, style):
|
|
|
|
|
|
|
| 9 |
try:
|
| 10 |
results = model.generate_image(
|
| 11 |
text_prompts=text_prompts, style=style, visualization=False)
|
|
|
|
|
|
|
|
|
|
| 12 |
return 'Success', results[:6]
|
| 13 |
except Exception as e:
|
| 14 |
error_text = str(e)
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
import gradio as gr
|
| 3 |
import paddlehub as hub
|
| 4 |
+
import time
|
| 5 |
|
| 6 |
|
| 7 |
model = hub.Module(directory='ernie_vilg')
|
| 8 |
|
| 9 |
def inference(text_prompts, style):
|
| 10 |
+
enter_module_time = time.time()
|
| 11 |
+
print('enter module time ', time.ctime(enter_module_time))
|
| 12 |
try:
|
| 13 |
results = model.generate_image(
|
| 14 |
text_prompts=text_prompts, style=style, visualization=False)
|
| 15 |
+
exist_module_time = time.time()
|
| 16 |
+
print('Exist module time ',time.ctime(exist_module_time))
|
| 17 |
+
print('module exectution time ', exist_module_time-enter_module_time)
|
| 18 |
return 'Success', results[:6]
|
| 19 |
except Exception as e:
|
| 20 |
error_text = str(e)
|
ernie_vilg/__pycache__/module.cpython-37.pyc
CHANGED
|
Binary files a/ernie_vilg/__pycache__/module.cpython-37.pyc and b/ernie_vilg/__pycache__/module.cpython-37.pyc differ
|
|
|
ernie_vilg/module.py
CHANGED
|
@@ -76,6 +76,8 @@ class ErnieVilG:
|
|
| 76 |
if not os.path.exists(output_dir):
|
| 77 |
os.makedirs(output_dir, exist_ok=True)
|
| 78 |
token = self.token
|
|
|
|
|
|
|
| 79 |
create_url = 'https://wenxin.baidu.com/younger/portal/api/rest/1.0/ernievilg/v1/txt2img?from=paddlehub'
|
| 80 |
get_url = 'https://wenxin.baidu.com/younger/portal/api/rest/1.0/ernievilg/v1/getImg?from=paddlehub'
|
| 81 |
if isinstance(text_prompts, str):
|
|
@@ -108,8 +110,12 @@ class ErnieVilG:
|
|
| 108 |
else:
|
| 109 |
print(res['msg'])
|
| 110 |
raise RuntimeError(res['msg'])
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
start_time = time.time()
|
|
|
|
| 113 |
process_bar = tqdm(total=100, unit='%')
|
| 114 |
results = {}
|
| 115 |
first_iter = True
|
|
@@ -165,9 +171,11 @@ class ErnieVilG:
|
|
| 165 |
for taskid in has_done:
|
| 166 |
taskids.remove(taskid)
|
| 167 |
end_time = time.time() #debug code
|
| 168 |
-
print('
|
|
|
|
| 169 |
start_save_time = time.time() #debug code
|
| 170 |
print('Saving Images...')
|
|
|
|
| 171 |
result_images = []
|
| 172 |
for text, data in results.items():
|
| 173 |
for idx, imgdata in enumerate(data['imgUrls']):
|
|
@@ -186,6 +194,7 @@ class ErnieVilG:
|
|
| 186 |
break
|
| 187 |
print('Done')
|
| 188 |
end_save_time = time.time() #debug code
|
|
|
|
| 189 |
print('Download and decode images time', end_save_time-start_save_time)
|
| 190 |
return result_images
|
| 191 |
|
|
|
|
| 76 |
if not os.path.exists(output_dir):
|
| 77 |
os.makedirs(output_dir, exist_ok=True)
|
| 78 |
token = self.token
|
| 79 |
+
task_create_start_time = time.time()
|
| 80 |
+
print('task_create_start_time', time.ctime(task_create_start_time))
|
| 81 |
create_url = 'https://wenxin.baidu.com/younger/portal/api/rest/1.0/ernievilg/v1/txt2img?from=paddlehub'
|
| 82 |
get_url = 'https://wenxin.baidu.com/younger/portal/api/rest/1.0/ernievilg/v1/getImg?from=paddlehub'
|
| 83 |
if isinstance(text_prompts, str):
|
|
|
|
| 110 |
else:
|
| 111 |
print(res['msg'])
|
| 112 |
raise RuntimeError(res['msg'])
|
| 113 |
+
task_create_end_time = time.time()
|
| 114 |
+
print('task_create_end_time', time.ctime(task_create_end_time))
|
| 115 |
+
print('task create time:', task_create_end_time-task_create_start_time)
|
| 116 |
|
| 117 |
start_time = time.time()
|
| 118 |
+
print('task poll start time', time.ctime(start_time))
|
| 119 |
process_bar = tqdm(total=100, unit='%')
|
| 120 |
results = {}
|
| 121 |
first_iter = True
|
|
|
|
| 171 |
for taskid in has_done:
|
| 172 |
taskids.remove(taskid)
|
| 173 |
end_time = time.time() #debug code
|
| 174 |
+
print('task poll end time', time.ctime(end_time)) #debug code
|
| 175 |
+
print('poll time: ', end_time-start_time)
|
| 176 |
start_save_time = time.time() #debug code
|
| 177 |
print('Saving Images...')
|
| 178 |
+
print('download_start_time', time.ctime(start_save_time)) #debug code
|
| 179 |
result_images = []
|
| 180 |
for text, data in results.items():
|
| 181 |
for idx, imgdata in enumerate(data['imgUrls']):
|
|
|
|
| 194 |
break
|
| 195 |
print('Done')
|
| 196 |
end_save_time = time.time() #debug code
|
| 197 |
+
print('download_end_time', time.ctime(end_save_time)) #debug code
|
| 198 |
print('Download and decode images time', end_save_time-start_save_time)
|
| 199 |
return result_images
|
| 200 |
|