ruslanmv commited on
Commit
f405afd
1 Parent(s): a881912

First commit

Browse files
Files changed (5) hide show
  1. .gitignore +3 -0
  2. README.md +2 -2
  3. app.py +76 -0
  4. imagen.png +0 -0
  5. requirements.txt +14 -0
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ venv/
2
+ __pycache__/
3
+ *.py[cod]
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
- title: Text To Image Sdxl
3
  emoji: 🐢
4
  colorFrom: yellow
5
  colorTo: pink
6
  sdk: gradio
7
- sdk_version: 4.14.0
8
  app_file: app.py
9
  pinned: false
10
  ---
 
1
  ---
2
+ title: Text To Image SDXL
3
  emoji: 🐢
4
  colorFrom: yellow
5
  colorTo: pink
6
  sdk: gradio
7
+ sdk_version: 4.7.1
8
  app_file: app.py
9
  pinned: false
10
  ---
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Created by ruslanmv.com
2
+ ## Happy coding!
3
+ import gradio as gr
4
+ import torch
5
+ #import modin.pandas as pd
6
+ import numpy as np
7
+ from diffusers import DiffusionPipeline
8
+ from transformers import pipeline
9
+
10
+ pipe = pipeline('text-generation', model='daspartho/prompt-extend')
11
+
12
+ def extend_prompt(prompt):
13
+ return pipe(prompt+',', num_return_sequences=1)[0]["generated_text"]
14
+
15
+ def text_it(inputs):
16
+ return extend_prompt(inputs)
17
+
18
+
19
+
20
+ def load_pipeline(use_cuda):
21
+ device = "cuda" if use_cuda and torch.cuda.is_available() else "cpu"
22
+ if device == "cuda":
23
+ torch.cuda.max_memory_allocated(device=device)
24
+ torch.cuda.empty_cache()
25
+ pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
26
+ pipe.enable_xformers_memory_efficient_attention()
27
+ pipe = pipe.to(device)
28
+ torch.cuda.empty_cache()
29
+ else:
30
+ pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)
31
+ pipe = pipe.to(device)
32
+ return pipe
33
+
34
+ def genie(prompt="sexy woman", use_details=False,steps=2, seed=398231747038484200, use_cuda=False):
35
+ pipe = load_pipeline(use_cuda)
36
+ generator = np.random.seed(0) if seed == 0 else torch.manual_seed(seed)
37
+ if use_details:
38
+ extended_prompt = extend_prompt(prompt)
39
+ else:
40
+ extended_prompt=prompt
41
+ int_image = pipe(prompt=extended_prompt, generator=generator, num_inference_steps=steps, guidance_scale=0.0).images[0]
42
+ return int_image, extended_prompt
43
+
44
+ with gr.Blocks() as myface:
45
+ gr.HTML()
46
+ with gr.Row():
47
+ with gr.Row():
48
+ input_text = gr.Textbox(label='Prompt Text.', lines=1)
49
+ details_checkbox = gr.Checkbox(label="details", info="Generate Details?")
50
+ steps_slider = gr.Slider(1, maximum=5, value=2, step=1, label='Number of Iterations')
51
+ seed_slider = gr.Slider(minimum=0, step=1, maximum=999999999999999999, randomize=True)
52
+ cuda_checkbox = gr.Checkbox(label="cuda", info="Do you have cuda?")
53
+ with gr.Row():
54
+ generate_button = gr.Button("Generate")
55
+ with gr.Row():
56
+ output_image = gr.Image("./imagen.png")
57
+ output_text = gr.Textbox(label="Generated Text", lines=2)
58
+ generate_button.click(genie, inputs=[input_text,details_checkbox, steps_slider, seed_slider, cuda_checkbox], outputs=[output_image, output_text], concurrency_limit=10)
59
+
60
+ # Define the example
61
+ example = [["sexy woman", True ,2, 398231747038484200, ""],
62
+ ['''sexy woman, in a black bikini, white bra, highly detailed, d & d, fantasy, highly detailed, digital painting, trending on artstation, concept art, sharp focus, illustration, art by artgerm and greg rutkowski and fuji choko and viktoria gavrilenko''', False ,2, 304332410412655740, ""],
63
+ ['''sexy woman, D&D, fantasy, portrait, highly detailed, headshot, digital painting, trending on artstation, concept art, sharp focus, illustration, art by artgerm and greg rutkowski and magali villeneuve and wlop, ilya kuvshinov, octane render, 8 ''', False ,2, 747356768820251800, ""],
64
+ [''' sexy woman, worksafe, light blonde long hair, fully clothed, brown eyes, sitting on a chair, sitting by a reflective pool, in the style of ilya kuvshinov, very dark, cinematic dramatic atmosphere, artstation, detailed facial ''', False ,2, 398231747038484200, ""],
65
+ ['''sexy woman, medium shot, candid, red hair, 4 k, high definition, realistic, natural, highly detailed, photo realistic smooth, sharp, unreal engine 5, cinema4d, Blender, render photo-realistic, v-ray ''', False ,2, 398231747038484200, ""],
66
+ ]
67
+
68
+ with gr.Interface(
69
+ fn=genie,
70
+ inputs=[input_text,details_checkbox, steps_slider, seed_slider, cuda_checkbox],
71
+ outputs=[output_image, output_text],
72
+ title="Stable Diffusion Turbo with GPT",
73
+ description="Type your text and lets create an image, check the box details if you want a creative picture",
74
+ examples=example,
75
+ ) as iface:
76
+ iface.launch(inline=True, show_api=False, max_threads=200)
imagen.png ADDED
requirements.txt ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ diffusers==0.23.1
2
+ transformers
3
+ gradio==4.7.1
4
+ --extra-index-url https://download.pytorch.org/whl/cu121
5
+ torch==2.1.0
6
+ fastapi==0.104.0
7
+ uvicorn==0.23.2
8
+ Pillow==10.1.0
9
+ accelerate==0.24.0
10
+ compel==2.0.2
11
+ controlnet-aux==0.0.7
12
+ peft==0.6.0
13
+ xformers
14
+ hf_transfer