import gradio.inputs as gr import requests # Базовые настройки prompt = gr.Textbox(label="Prompt") models = gr.RadioButtons(options=["Bard", "DALL-E 2", "VQGAN+CLIP", "VQGAN", "CLIP", "InceptionV3"]) # Расширенные настройки negative_prompt = gr.Textbox(label="Negative Prompt") sampling_method = gr.RadioButtons(options=["random", "greedy", "nucleus", "top_k", "top_p"]) sampling_steps = gr.Number(label="Sampling Steps", min=1, max=1000, default=100) cfg_scale = gr.Number(label="CFG Scale", min=0.1, max=10.0, default=1.0) seed = gr.Number(label="Seed", min=0, max=2**31, default=0) # Улучшение качества algorithm = gr.RadioButtons(options=["nearest", "bilinear", "bicubic", "lanczos", "cubic", "mitchell"]) # Функция генерации изображения def generate_image(prompt, model, negative_prompt, sampling_method, sampling_steps, cfg_scale, seed): url = "https://api.huggingface.co/models/text-to-image/v1/generate" data = { "prompt": prompt, "model": model, "negative_prompt": negative_prompt, "sampling_method": sampling_method, "sampling_steps": sampling_steps, "cfg_scale": cfg_scale, "seed": seed, } response = requests.post(url, json=data) image = response.json()["image"] return image # Функция улучшения качества изображения def improve_quality(image, algorithm): url = "https://api.huggingface.co/models/text-to-image/v1/improve-quality" data = { "image": image, "algorithm": algorithm, } response = requests.post(url, json=data) image = response.json()["image"] return image # Основная функция def main(): gr.Interface( generate_image, inputs=[prompt, models, negative_prompt, sampling_method, sampling_steps, cfg_scale, seed], outputs=gr.outputs.Image(), title="Gradio Image Generator", tabs=[ gr.Tab("Базовые настройки", [prompt, models]), gr.Tab("Расширенные настройки", [negative_prompt, sampling_method, sampling_steps, cfg_scale, seed]), gr.Tab("Улучшение качества", [algorithm]), ], ).launch() if __name__ == "__main__": main()