File size: 6,205 Bytes
25ba393
 
265cdf3
9422171
25ba393
 
 
 
 
 
 
 
 
8e810f0
25ba393
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8e810f0
92348ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25ba393
92348ee
 
25ba393
92348ee
 
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import streamlit as st
from PIL import Image
from diffusers import StableDiffusionPipeline, ControlNetModel, DDIMScheduler, LMSDiscreteScheduler, UNet2DConditionModel, DiffusionPipeline
from diffusers import DDPMScheduler, DDPMSchedulerV2, PNDMScheduler
from transformers import AutoModelForCausalLM, AutoTokenizer, AutoModelForSeq2SeqLM, LlamaTokenizerFast, LlamaForCausalLM
from accelerate import Accelerator
import torch
from peft import PeftModel, LoraConfig, get_peft_model, prepare_model_for_int8_training, prepare_model_for_int8_bf16_training

# Define a dictionary with all available models, schedulers, features, weights, and adapters
model_dict = {
    "Stable Diffusion": {
        "Models": [
            "stabilityai/stable-diffusion-3-medium"
            "CompVis/stable-diffusion-v1-4",
            "stabilityai/stable-diffusion-2-1",
            "runwayml/stable-diffusion-v1-5",
            "runwayml/stable-diffusion-inpainting",
            "runwayml/stable-diffusion-video-v1-5",
            "stabilityai/stable-diffusion-2-base"
        ],
        "Schedulers": [
            "DDIMScheduler",
            "LMSDiscreteScheduler"
        ],
        "Features": [
            "Unconditional image generation",
            "Text-to-image",
            "Image-to-image",
            "Inpainting",
            "Text or image-to-video",
            "Depth-to-image"
        ],
        "Adapters": [
            "ControlNet",
            "T2I-Adapter"
        ],
        "Weights": [
            "Stable Diffusion XL",
            "SDXL Turbo",
            "Kandinsky",
            "IP-Adapter",
            "ControlNet",
            "Latent Consistency Model",
            "Textual inversion",
            "Shap-E",
            "DiffEdit",
            "Trajectory Consistency Distillation-LoRA",
            "Stable Video Diffusion",
            "Marigold Computer Vision"
        ]
    },
    "Llama": {
        "Models": [
            "decapoda-research/llama-7b-hf",
            "decapoda-research/llama-13b-hf",
            "decapoda-research/llama-30b-hf",
            "decapoda-research/llama-65b-hf"
        ],
        "Tokenizers": [
            "LlamaTokenizerFast"
        ],
        "Features": [
            "AutoPipeline",
            "Train a diffusion model",
            "Load LoRAs for inference",
            "Accelerate inference of text-to-image diffusion models",
            "LOAD PIPELINES AND ADAPTERS",
            "Load community pipelines and components",
            "Load schedulers and models",
            "Model files and layouts",
            "Load adapters",
            "Push files to the Hub",
            "GENERATIVE TASKS",
            "Unconditional image generation",
            "Text-to-image",
            "Image-to-image",
            "Inpainting",
            "Text or image-to-video",
            "Depth-to-image",
            "INFERENCE TECHNIQUES",
            "Overview",
            "Distributed inference with multiple GPUs",
            "Merge LoRAs",
            "Scheduler features",
            "Pipeline callbacks",
            "Reproducible pipelines",
            "Controlling image quality",
            "Prompt techniques",
            "ADVANCED INFERENCE",
            "Outpainting",
            "SPECIFIC PIPELINE EXAMPLES",
            "Stable Diffusion XL",
            "SDXL Turbo",
            "Kandinsky",
            "IP-Adapter",
            "ControlNet",
            "T2I-Adapter",
            "Latent Consistency Model",
            "Textual inversion",
            "Shap-E",
            "DiffEdit",
            "Trajectory Consistency Distillation-LoRA",
            "Stable Video Diffusion",
            "Marigold Computer Vision"
        ],
        "Weights": [
            "LoRA weights"
        ]
    }
}

model_type = st.selectbox("Select a model type:", list(model_dict.keys()))

if model_type == "Stable Diffusion":
    model = st.selectbox("Select a Stable Diffusion model:", model_dict[model_type]["Models"])
    scheduler = st.selectbox("Select a scheduler:", model_dict[model_type]["Schedulers"])
    feature = st.selectbox("Select a feature:", model_dict[model_type]["Features"])
    adapter = st.selectbox("Select an adapter:", model_dict[model_type]["Adapters"])
    weight = st.selectbox("Select a weight:", model_dict[model_type]["Weights"])

    if st.button("Generate Images"):
        st.write("Generating images...")

        pipe = StableDiffusionPipeline.from_pretrained(model)
        pipe.scheduler = eval(scheduler)()

        if adapter == "ControlNet":
            controlnet = ControlNetModel.from_pretrained("lllyasviel/control_v11e_sd15_openpose")
            pipe = pipe.to_controlnet(controlnet)

        # Define the prompt and number of images to generate
        prompt = st.text_input("Enter a prompt:")
        num_images = st.slider("Number of images to generate", min_value=1, max_value=10, value=1)

        # Generate the images
        images = pipe(prompt, num_images=num_images, guidance_scale=7.5).images

        # Display the generated images
        cols = st.columns(num_images)
        for i, image in enumerate(images):
            cols[i].image(image, caption=f"Image {i+1}", use_column_width=True)

if model_type == "Llama":
    model = st.selectbox("Select a Llama model:", model_dict[model_type]["Models"])
    tokenizer = st.selectbox("Select a tokenizer:", model_dict[model_type]["Tokenizers"])
    feature = st.selectbox("Select a feature:", model_dict[model_type]["Features"])
    weight = st.selectbox("Select a weight:", model_dict[model_type]["Weights"])

    if st.button("Generate Text"):
        st.write("Generating text...")

        tokenizer = AutoTokenizer.from_pretrained(tokenizer)
        model = AutoModelForCausalLM.from_pretrained(model)

        input_text = st.text_area("Enter a prompt:")

        # Tokenize the input text
        inputs = tokenizer(input_text, return_tensors="pt")

        # Generate the text
        output = model.generate(**inputs)

        # Decode the generated text
        generated_text = tokenizer.decode(output[0], skip_special_tokens=True)

        st.write("Generated Text:")
        st.write(generated_text)