Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

what is next #6

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions inferencer/strategy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .what_is_next import what_is_next
from .what_is_dish import what_is_dish
from .what_is_step_img_doing import what_is_step_img_doing
from .what_are_step_imgs_doing import what_are_step_imgs_doing
Expand All @@ -12,4 +13,5 @@
'what_are_components_nested': what_are_components_nested,
'what_are_components_flat': what_are_components_flat,
'how_to_sort_step_imgs': how_to_sort_step_imgs,
'what_is_next': what_is_next,
}
45 changes: 45 additions & 0 deletions inferencer/strategy/what_is_next.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os
from typing import List, Any, Dict

from utils import download_img, make_data_dict, ID_COUNTER, LOGGER
from configs import IMG_SAVE_PATH

def what_is_next(data: Dict[str, Any], **kwargs) -> List[Any]:
results = []
for idx, cur_step in enumerate(data['steps']):
img_file = os.path.join(IMG_SAVE_PATH, f"{data['id']}_{str(ID_COUNTER)}_{what_is_next.__name__}_{idx}.jpg")

if os.path.isfile(img_file):
LOGGER.warning(f'img has been downloaded in {what_is_next.__name__}: [{img_file}]')

if not download_img(
cur_step['img'],
img_file
):
LOGGER.debug(f"img download failed, url: [{cur_step['img']}]")
continue

if idx == len(data['steps'])-1:
results.append(
make_data_dict(
cur_id=str(ID_COUNTER),
cur_conversations=[
f"图:<img>{img_file}</img>,接下来做什么?",
f"已经完成了"
]
)
)

else:
results.append(
make_data_dict(
cur_id=str(ID_COUNTER),
cur_conversations=[
f"图:<img>{img_file}</img>,接下来做什么?",
f"接下来应该" + ''.join(f"{data['steps'][i]['description']}"[1:] for i in
range(idx+1, len(data['steps'])))
]
)
)
ID_COUNTER.increment()
return results
Loading