51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
import gradio as gr
|
|
from clip_interrogator import Config, Interrogator
|
|
from share_btn import community_icon_html, loading_icon_html, share_js
|
|
from gradio.themes.utils import sizes
|
|
|
|
|
|
theme = gr.themes.Default(radius_size=sizes.radius_none).set(
|
|
block_label_text_color = '#4D63FF',
|
|
block_title_text_color = '#4D63FF',
|
|
button_primary_text_color = '#4D63FF',
|
|
button_primary_background_fill='#FFFFFF',
|
|
button_primary_border_color='#4D63FF',
|
|
button_primary_background_fill_hover='#EDEFFF',
|
|
)
|
|
|
|
MODELS = ['ViT-L (best for Stable Diffusion 1.*)']
|
|
|
|
config = Config(clip_model_name="ViT-L-14/openai")
|
|
ci_vitl = Interrogator(config)
|
|
|
|
|
|
def image_to_prompt(image):
|
|
ci = ci_vitl
|
|
|
|
ci.config.blip_num_beams = 64
|
|
ci.config.chunk_size = 2048
|
|
ci.config.flavor_intermediate_count = 2048
|
|
|
|
image = image.convert('RGB')
|
|
prompt = ci.interrogate(image)
|
|
|
|
return prompt, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
|
|
|
|
|
with gr.Blocks(theme=theme, css="footer {visibility: hidden}") as demo:
|
|
gr.Markdown("""
|
|
<div align='center' ><font size='60'>根据图片生成prompt</font></div>
|
|
""")
|
|
with gr.Row():
|
|
with gr.Column():
|
|
box1 = gr.Image(label="图片", type="pil")
|
|
with gr.Row():
|
|
button = gr.Button("提交", variant="primary")
|
|
box2 = gr.Textbox(label="文本")
|
|
|
|
button.click(fn=image_to_prompt, inputs=box1, outputs=box2)
|
|
examples = gr.Examples(examples=[['example01.jpg'], ['example02.jpg']], inputs=[box1], label="例子")
|
|
|
|
|
|
demo.queue().launch(server_name = "0.0.0.0")
|