Skip to content

Commit

Permalink
can upload train images to s3 via webui
Browse files Browse the repository at this point in the history
  • Loading branch information
xie river committed Mar 30, 2023
1 parent 9e45f12 commit 5301172
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions localizations/zh_CN.json
Expand Up @@ -840,5 +840,10 @@
"Save Preview(s) Frequency (Epochs)": "保存预览频率 (Epochs)",
"A generic prompt used to generate a sample image to verify model fidelity.": "用于生成样本图像以验证模型保真度的通用提示。",
"Job detail":"训练任务详情",
"S3 bucket name for uploading train images":"上传训练图片集的S3桶名",
"Output S3 folder":"S3文件夹目录",
"Upload Train Images to S3":"上传训练图片到S3",
"Error, please configure a S3 bucket at settings page first":"失败,请先到设置页面配置S3桶名",
"Upload":"上传",
"--------": "--------"
}
1 change: 1 addition & 0 deletions modules/shared.py
Expand Up @@ -423,6 +423,7 @@ def refresh_sagemaker_endpoints(username):
}))

options_templates.update(options_section(('saving-paths', "Paths for saving"), {
"train_files_s3bucket":OptionInfo("","S3 bucket name for uploading train images",component_args=hide_dirs),
"outdir_samples": OptionInfo("", "Output directory for images; if empty, defaults to three directories below", component_args=hide_dirs),
"outdir_txt2img_samples": OptionInfo("outputs/txt2img-images", 'Output directory for txt2img images', component_args=hide_dirs),
"outdir_img2img_samples": OptionInfo("outputs/img2img-images", 'Output directory for img2img images', component_args=hide_dirs),
Expand Down
24 changes: 23 additions & 1 deletion modules/ui.py
Expand Up @@ -11,7 +11,8 @@
import time
import traceback
from functools import partial, reduce

import boto3
import datetime
import gradio as gr
import gradio.routes
import gradio.utils
Expand Down Expand Up @@ -1463,6 +1464,27 @@ def update_orig(image, state):

with gr.Row().style(equal_height=False):
with gr.Tabs(elem_id="train_tabs"):
## Begin add s3 images upload interface by River
s3 = boto3.client('s3')
def upload_to_s3(imgs):
username = shared.username
timestamp = datetime.datetime.now().strftime('%Y-%m-%dT%H-%M-%S')
bucket_name = opts.train_files_s3bucket
if bucket_name == '':
return 'Error, please configure a S3 bucket at settings page first'
folder_name = f"train-images/{username}/{timestamp}"
for i, img in enumerate(imgs):
filename = img.name.split('/')[-1]
object_name = f"{folder_name}/{filename}"
s3.upload_file(img.name, bucket_name, object_name)
return f"{len(imgs)} images uploaded to S3 folder: s3://{bucket_name}/{folder_name}"

with gr.Tab(label="Upload Train Images to S3"):
upload_files = gr.Files(label="Files")
url_output = gr.Textbox(label="Output S3 folder")
sub_btn = gr.Button("Upload")
sub_btn.click(fn=upload_to_s3, inputs=upload_files, outputs=url_output)
## End add s3 images upload interface by River
with gr.Tab(label="Train Embedding"):
gr.HTML(value="<p style='margin-bottom: 0.7em'>Train an embedding; you must specify a directory with a set of 1:1 ratio images <a href=\"https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Textual-Inversion\" style=\"font-weight:bold;\">[wiki]</a></p>")

Expand Down

0 comments on commit 5301172

Please sign in to comment.