Skip to content

Commit

Permalink
Component Text2Image add float math judge (#474)
Browse files Browse the repository at this point in the history
* add math judge

* update

* update ut

* update doc
  • Loading branch information
MrChengmo authored Aug 17, 2024
1 parent 39cde74 commit f9b3afd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions appbuilder/core/components/text_to_image/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""
import time
import json
import math

from appbuilder.core.component import Component
from appbuilder.core.message import Message
Expand Down Expand Up @@ -105,9 +106,10 @@ def run(
request.task_id = taskId
text2ImageQueryResponse = self.queryText2ImageData(request, request_id=request_id)
if text2ImageQueryResponse.data.task_progress is not None:
task_progress = text2ImageQueryResponse.data.task_progress
if task_progress == 1:
task_progress = float(text2ImageQueryResponse.data.task_progress)
if math.isclose(1.0, task_progress, rel_tol=1e-9, abs_tol=0.0):
break

# NOTE(chengmo):文生图组件的返回时间在10s以上,查询过于频繁会被限流,导致异常报错
# 此处采用 yangyongzhen老师提供的方案,前三次查询间隔3s,后三次查询间隔逐渐增大
if task_request_time <= 3:
Expand Down
8 changes: 4 additions & 4 deletions appbuilder/core/components/text_to_image/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ class Text2ImageQueryData(proto.Message):
任务 ID.
task_status(str):
计算总状态。有 INIT(初始化),WAIT(排队中), RUNNING(生成中), FAILED(失败), SUCCESS(成功)四种状态,只有 SUCCESS 为成功状态。
task_progress(int):
图片生成总进度,进度包含2种,0为未处理完,1为处理完成。
task_progress(float):
图片生成总进度,0到1之间的浮点数表示进度,0为未处理完,1为处理完成。
sub_task_result_list(Text2ImageSubTaskResultList):
子任务生成结果列表。
"""
Expand Down Expand Up @@ -216,8 +216,8 @@ class Text2ImageSubTaskResultList(proto.Message):
参数:
sub_task_status(int):
单风格图片状态。有 INIT(初始化),WAIT(排队中), RUNNING(生成中), FAILED(失败), SUCCESS(成功)四种状态,只有 SUCCESS 为成功状态。
sub_task_progress(int):
单任务图片生成进度,进度包含2种,0为未处理完,1为处理完成。
sub_task_progress(float):
单任务图片生成进度,0到1之间的浮点数表示进度,0为未处理完,1为处理完成。
sub_task_error_code(str):
单风格任务错误码。0:正常;501:文本黄反拦截;201:模型生图失败。
final_image_list(Text2ImageFinalImageList):
Expand Down
2 changes: 1 addition & 1 deletion appbuilder/tests/test_text_to_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_extract_img_urls(self):
"""
response = Text2ImageQueryResponse()
response.data.task_progress = 1
response.data.task_progress = 1.0
response.data.sub_task_result_list = [{'final_image_list': [{'img_url': 'http://example.com'}]}]
img_urls = self.text2Image.extract_img_urls(response)
self.assertEqual(img_urls, ['http://example.com'])
Expand Down

0 comments on commit f9b3afd

Please sign in to comment.