File size: 1,823 Bytes
dd99792
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2aea04c
 
4f3d38a
2aea04c
dd99792
 
87d6a6d
dd99792
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28be401
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# coding=utf-8
#
# Copyright 2024 Toshihiko Aoki
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import torch
from diffusers import AutoPipelineForText2Image, LCMScheduler
from llama_cpp import Llama
import gradio as gr

width = 512
height = 512
num_inference_steps = 4
guidance_scale = 1.0

from openvino_pipe import LatentConsistencyEngine
pipe = LatentConsistencyEngine(
    "sd-1.5-lcm-openvino"
)

llm = Llama(
    model_path="llm-jp-1.3b-v1.0_staircaptions-FT_Q2_K.gguf",
)

def ja2prompt(ja_prompt):
    response = llm(f"### Instruction:\n{ja_prompt}\n### Response:\n", max_tokens=128)
    return response['choices'][0]['text']


def prompt2img(sd_prompt):
    return pipe(
        sd_prompt,
        num_inference_steps=num_inference_steps,
        guidance_scale=1.0,
    ).images[0]


with gr.Blocks(title="tiny sd web-ui") as demo:
    gr.Markdown(f"## Japanese translation and hallucinations for Stable Diffusion")
    with gr.Row():
        with gr.Column(scale=3):
            ja = gr.Text(label="ζ—₯本θͺž")
            translate = gr.Button("倉換")
            prompt = gr.Text(label="γƒ—γƒ­γƒ³γƒ—γƒˆ")
        with gr.Column(scale=2):
            result = gr.Image()
            t2i = gr.Button("η”Ÿζˆ")
    translate.click(ja2prompt, ja, prompt)
    t2i.click(prompt2img, prompt, result)

demo.launch()