ruslanmv commited on
Commit
0690d39
1 Parent(s): a38f0a0

First commit

Browse files
Files changed (5) hide show
  1. .gitignore +3 -0
  2. README.md +1 -1
  3. app.py +85 -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
@@ -4,7 +4,7 @@ emoji: 🐠
4
  colorFrom: purple
5
  colorTo: pink
6
  sdk: gradio
7
- sdk_version: 4.14.0
8
  app_file: app.py
9
  pinned: false
10
  ---
 
4
  colorFrom: purple
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,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ import modin.pandas as pd
4
+ import numpy as np
5
+ from diffusers import DiffusionPipeline
6
+ from transformers import pipeline
7
+
8
+ pipe = pipeline('text-generation', model='daspartho/prompt-extend')
9
+
10
+ def extend_prompt(prompt):
11
+ return pipe(prompt+',', num_return_sequences=1)[0]["generated_text"]
12
+
13
+ def text_it(inputs):
14
+ return extend_prompt(inputs)
15
+
16
+
17
+ def load_pipeline(use_cuda):
18
+ device = "cuda" if use_cuda and torch.cuda.is_available() else "cpu"
19
+
20
+ if device == "cuda":
21
+ torch.cuda.max_memory_allocated(device=device)
22
+ torch.cuda.empty_cache()
23
+ pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
24
+ pipe.enable_xformers_memory_efficient_attention()
25
+ pipe = pipe.to(device)
26
+ torch.cuda.empty_cache()
27
+ else:
28
+ pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)
29
+ pipe = pipe.to(device)
30
+
31
+ return pipe
32
+
33
+ def genie(prompt="sexy woman", use_details=True,steps=2, seed=398231747038484200, use_cuda=False):
34
+ pipe = load_pipeline(use_cuda)
35
+ generator = np.random.seed(0) if seed == 0 else torch.manual_seed(seed)
36
+ if use_details:
37
+ extended_prompt = extend_prompt(prompt)
38
+ else:
39
+ extended_prompt=prompt
40
+ int_image = pipe(prompt=extended_prompt, generator=generator, num_inference_steps=steps, guidance_scale=0.0).images[0]
41
+ return int_image, extended_prompt
42
+
43
+
44
+ # Custom HTML for the interface
45
+ html_code = '''
46
+ <style>
47
+ body {
48
+ background-color: #F0F0F0;
49
+ }
50
+ </style>
51
+ <h1 style="color:black; text-align:center;">Stable Diffusion Turbo with GPT</h1>
52
+ '''
53
+
54
+ with gr.Blocks() as myface:
55
+ gr.HTML(html_code) # Add the custom HTML
56
+
57
+ with gr.Row():
58
+ input_text = gr.Textbox(label='Text prompt.', lines=1)
59
+
60
+ with gr.Row():
61
+ details_checkbox = gr.Checkbox(label="details", info="Generate Details?")
62
+ steps_slider = gr.Slider(1, maximum=5, value=2, step=1, label='Number of Iterations')
63
+ seed_slider = gr.Slider(minimum=0, step=1, maximum=999999999999999999, randomize=False, value=398231747038484200)
64
+ cuda_checkbox = gr.Checkbox(label="cuda", info="Do you have cuda?")
65
+ with gr.Row():
66
+ generate_button = gr.Button("Generate")
67
+ with gr.Row():
68
+ output_image1 = gr.Image()
69
+ output_image2 = gr.Image()
70
+ with gr.Row():
71
+ output_text1 = gr.Textbox(label="Generated Text", lines=2)
72
+ output_text2 = gr.Textbox(label="Generated Text", lines=2)
73
+
74
+ with gr.Row():
75
+ output_image3 = gr.Image()
76
+ output_image4 = gr.Image()
77
+ with gr.Row():
78
+ output_text3 = gr.Textbox(label="Generated Text", lines=2)
79
+ output_text4 = gr.Textbox(label="Generated Text", lines=2)
80
+
81
+ generate_button.click(genie, inputs=[input_text, details_checkbox, steps_slider, seed_slider, cuda_checkbox], outputs=[output_image1, output_text1], concurrency_limit=10)
82
+ generate_button.click(genie, inputs=[input_text, details_checkbox, steps_slider, seed_slider, cuda_checkbox], outputs=[output_image2, output_text2], concurrency_limit=10)
83
+ generate_button.click(genie, inputs=[input_text, details_checkbox, steps_slider, seed_slider, cuda_checkbox], outputs=[output_image3, output_text3], concurrency_limit=10)
84
+ generate_button.click(genie, inputs=[input_text, details_checkbox, steps_slider, seed_slider, cuda_checkbox], outputs=[output_image4, output_text4], concurrency_limit=10)
85
+ myface.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