FreeverseAI commited on
Commit
d80c23a
·
verified ·
1 Parent(s): 3087dc7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -28
app.py CHANGED
@@ -1,32 +1,34 @@
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
 
7
- device = "cuda" if torch.cuda.is_available() else "cpu"
 
 
8
 
9
- if torch.cuda.is_available():
10
- torch.cuda.max_memory_allocated(device=device)
11
- torch.cuda.empty_cache()
12
- pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
13
- pipe.enable_xformers_memory_efficient_attention()
14
- pipe = pipe.to(device)
15
- torch.cuda.empty_cache()
16
- else:
17
- pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)
18
- pipe = pipe.to(device)
19
-
20
- def genie (prompt, steps, seed):
21
- generator = np.random.seed(0) if seed == 0 else torch.manual_seed(seed)
22
- int_image = pipe(prompt=prompt, generator=generator, num_inference_steps=steps, guidance_scale=0.0).images[0]
23
- return int_image
24
-
25
- gr.Interface(fn=genie, inputs=[gr.Textbox(label='What you want the AI to generate. 77 Token Limit.'),
26
- gr.Slider(1, maximum=5, value=2, step=1, label='Number of Iterations'),
27
- gr.Slider(minimum=0, step=1, maximum=999999999999999999, randomize=True),
28
- ],
29
- outputs='image',
30
- title="Stable Diffusion Turbo CPU or GPU",
31
- description="SDXL Turbo CPU or GPU. Currently running on CPU. <br><br><b>WARNING: This model is capable of producing NSFW (Softcore) images.</b>",
32
- article = "If You Enjoyed this Demo and would like to Donate, you can send to any of these Wallets. <br>BTC: bc1qzdm9j73mj8ucwwtsjx4x4ylyfvr6kp7svzjn84 <br>3LWRoKYx6bCLnUrKEdnPo3FCSPQUSFDjFP <br>DOGE: DK6LRc4gfefdCTRk9xPD239N31jh9GjKez <br>SHIB (BEP20): 0xbE8f2f3B71DFEB84E5F7E3aae1909d60658aB891 <br>PayPal: https://www.paypal.me/ManjushriBodhisattva <br>ETH: 0xbE8f2f3B71DFEB84E5F7E3aae1909d60658aB891 <br>Code Monkey: <a href=\"https://huggingface.co/Manjushri\">Manjushri</a>").launch(debug=True, max_threads=80)
 
 
 
1
  import gradio as gr
2
  import torch
3
+ from diffusers import AutoPipelineForText2Image
 
 
4
 
5
+ # Model configuration
6
+ MODEL_ID = "stabilityai/sd-turbo"
7
+ DEVICE = "cpu"
8
 
9
+ pipe = AutoPipelineForText2Image.from_pretrained(
10
+ MODEL_ID,
11
+ torch_dtype=torch.float32,
12
+ )
13
+ pipe.to(DEVICE)
14
+
15
+ def generate_image(prompt: str):
16
+ if not prompt.strip():
17
+ return None
18
+ result = pipe(
19
+ prompt,
20
+ num_inference_steps=4, # Fast rendering
21
+ guidance_scale=0.0, # More realistic, less overexposed
22
+ )
23
+ return result.images[0]
24
+
25
+ demo = gr.Interface(
26
+ fn=generate_image,
27
+ inputs=gr.Textbox(label="Enter your image prompt"),
28
+ outputs=gr.Image(label="Generated Image"),
29
+ title="Freeverse AI Studio 🎨",
30
+ description="Generate ultra-realistic AI images using Stable Diffusion Turbo (Freeverse AI).",
31
+ )
32
+
33
+ if __name__ == "__main__":
34
+ demo.launch()