Commit 2fd02f85 authored by chenpangpang's avatar chenpangpang
Browse files

feat: gradio界面改成中文

parent 2c02012d
......@@ -59,6 +59,7 @@ pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
pipe.fuse_lora()
pipe.to(device)
def generate_image(upload_images, prompt, negative_prompt, aspect_ratio_name, style_name, num_steps,
style_strength_ratio, num_outputs, guidance_scale, seed, progress=gr.Progress(track_tqdm=True)):
# check the trigger word
......@@ -163,52 +164,21 @@ logo = r"""
<center><img src='https://photo-maker.github.io/assets/logo.png' alt='PhotoMaker logo' style="width:80px; margin-bottom:10px"></center>
"""
title = r"""
<h1 align="center">PhotoMaker: Customizing Realistic Human Photos via Stacked ID Embedding</h1>
<h1 align="center">PhotoMaker:通过少量样本提取的个性化信息,在自然语言描述引导下,生成逼真的照片或者艺术化的图片</h1>
"""
description = r"""
<b>Official 🤗 Gradio demo</b> for <a href='https://github.com/TencentARC/PhotoMaker' target='_blank'><b>PhotoMaker: Customizing Realistic Human Photos via Stacked ID Embedding</b></a>.<br>
<br>
For stylization, you could use our other gradio demo [PhotoMaker-Style](https://huggingface.co/spaces/TencentARC/PhotoMaker-Style).
<br>
❗️❗️❗️[<b>Important</b>] Personalization steps:<br>
1️⃣ Upload images of someone you want to customize. One image is ok, but more is better. Although we do not perform face detection, the face in the uploaded image should <b>occupy the majority of the image</b>.<br>
2️⃣ Enter a text prompt, making sure to <b>follow the class word</b> you want to customize with the <b>trigger word</b>: `img`, such as: `man img` or `woman img` or `girl img`.<br>
3️⃣ Choose your preferred style template.<br>
4️⃣ Click the <b>Submit</b> button to start customizing.
"""
article = r"""
If PhotoMaker is helpful, please help to ⭐ the <a href='https://github.com/TencentARC/PhotoMaker' target='_blank'>Github Repo</a>. Thanks!
[![GitHub Stars](https://img.shields.io/github/stars/TencentARC/PhotoMaker?style=social)](https://github.com/TencentARC/PhotoMaker)
---
📝 **Citation**
<br>
If our work is useful for your research, please consider citing:
```bibtex
@article{li2023photomaker,
title={PhotoMaker: Customizing Realistic Human Photos via Stacked ID Embedding},
author={Li, Zhen and Cao, Mingdeng and Wang, Xintao and Qi, Zhongang and Cheng, Ming-Ming and Shan, Ying},
booktitle={IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
year={2024}
}
```
📋 **License**
<br>
Apache-2.0 LICENSE. Please refer to the [LICENSE file](https://huggingface.co/TencentARC/PhotoMaker/blob/main/LICENSE) for details.
📧 **Contact**
<br>
If you have any questions, please feel free to reach me out at <b>zhenli1031@gmail.com</b>.
个性化步骤:<br>
1️⃣ 上传您想要自定义的某个人的图像。一张或多张图片都行,建议多张。此工具不进行人脸检测,上传图像中的人脸应该占据图像的大部分。<br>
2️⃣ 输入文本提示符,确保按照您想要自定义的类单词使用触发词: `img`, 例如: `man img` 、 `woman img` 或 `girl img`。<br>
3️⃣ 选择您喜欢的风格模板。<br>
4️⃣ 单击提交按钮开始自定义。
"""
tips = r"""
### Usage tips of PhotoMaker
1. Upload more photos of the person to be customized to **improve ID fidelty**. If the input is Asian face(s), maybe consider adding 'asian' before the class word, e.g., `asian woman img`
2. When stylizing, does the generated face look too realistic? Try switching to our **other gradio demo** [PhotoMaker-Style](https://huggingface.co/spaces/TencentARC/PhotoMaker-Style). Adjust the **Style strength** to 30-50, the larger the number, the less ID fidelty, but the stylization ability will be better.
3. For **faster** speed, reduce the number of generated images and sampling steps. However, please note that reducing the sampling steps may compromise the ID fidelity.
### 使用技巧
1. 上传多张要定制的人的照片,以**提高身份识别精度**。如果输入是亚洲面孔,也许可以考虑在类单词之前添加“asian”,例如`asian woman img`
2. 为了**更快**的速度,减少生成的图像数量和采样步骤。但是,请注意,减少采样步骤可能会降低ID保真度。
"""
# We have provided some generate examples and comparisons at: [this website]().
# 3. Don't make the prompt too long, as we will trim it if it exceeds 77 tokens.
......@@ -229,21 +199,21 @@ with gr.Blocks(css=css) as demo:
with gr.Row():
with gr.Column():
files = gr.Files(
label="Drag (Select) 1 or more photos of your face",
label="上传/选择一张或多张人脸照片",
file_types=["image"]
)
uploaded_files = gr.Gallery(label="Your images", visible=False, columns=5, rows=1, height=200)
uploaded_files = gr.Gallery(label="你的图片", visible=False, columns=5, rows=1, height=200)
with gr.Column(visible=False) as clear_button:
remove_and_reupload = gr.ClearButton(value="Remove and upload new ones", components=files, size="sm")
remove_and_reupload = gr.ClearButton(value="移除以及重新上传", components=files, size="sm")
prompt = gr.Textbox(label="Prompt",
info="Try something like 'a photo of a man/woman img', 'img' is the trigger word.",
info="尝试类似'a photo of a man/woman img'的词, 'img'是触发词",
placeholder="A photo of a [man/woman img]...")
style = gr.Dropdown(label="Style template", choices=STYLE_NAMES, value=DEFAULT_STYLE_NAME)
aspect_ratio = gr.Dropdown(label="Output aspect ratio", choices=ASPECT_RATIO_LABELS,
style = gr.Dropdown(label="风格", choices=STYLE_NAMES, value=DEFAULT_STYLE_NAME)
aspect_ratio = gr.Dropdown(label="输出纵横比", choices=ASPECT_RATIO_LABELS,
value=DEFAULT_ASPECT_RATIO)
submit = gr.Button("Submit")
submit = gr.Button("提交")
with gr.Accordion(open=False, label="Advanced Options"):
with gr.Accordion(open=False, label="高级选项"):
negative_prompt = gr.Textbox(
label="Negative Prompt",
placeholder="low quality",
......@@ -286,8 +256,8 @@ with gr.Blocks(css=css) as demo:
)
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
with gr.Column():
gallery = gr.Gallery(label="Generated Images")
usage_tips = gr.Markdown(label="Usage tips of PhotoMaker", value=tips, visible=False)
gallery = gr.Gallery(label="生成图片")
usage_tips = gr.Markdown(label="使用技巧", value=tips, visible=False)
files.upload(fn=swap_to_gallery, inputs=files, outputs=[uploaded_files, clear_button, files])
remove_and_reupload.click(fn=remove_back_to_files, outputs=[uploaded_files, clear_button, files])
......@@ -316,6 +286,4 @@ with gr.Blocks(css=css) as demo:
outputs=[uploaded_files, clear_button, files],
)
gr.Markdown(article)
demo.launch(server_name='0.0.0.0', share=True)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment