Adapters
English
art
noxo8888 commited on
Commit
94a7d1f
·
verified ·
1 Parent(s): 7e42cb0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import StableDiffusionXLPipeline
4
+ from datetime import datetime
5
+ import os
6
+
7
+ class RafayyAI:
8
+ def __init__(self):
9
+ self.model = StableDiffusionXLPipeline.from_pretrained(
10
+ "stabilityai/stable-diffusion-xl-base-1.0",
11
+ torch_dtype=torch.float16,
12
+ use_safetensors=True,
13
+ variant="fp16"
14
+ )
15
+ if torch.cuda.is_available():
16
+ self.model = self.model.to("cuda")
17
+
18
+ def generate_image(self, prompt, negative_prompt=""):
19
+ # Generate unique filename
20
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
21
+ filename = f"generated_{timestamp}.png"
22
+
23
+ # Generate image
24
+ image = self.model(
25
+ prompt=prompt,
26
+ negative_prompt=negative_prompt,
27
+ num_inference_steps=30,
28
+ guidance_scale=7.5
29
+ ).images[0]
30
+
31
+ # Save image
32
+ image.save(filename)
33
+ return filename
34
+
35
+ # Initialize the AI
36
+ rafayy = RafayyAI()
37
+
38
+ # Create Gradio interface
39
+ def generate(prompt, negative_prompt=""):
40
+ return rafayy.generate_image(prompt, negative_prompt)
41
+
42
+ demo = gr.Interface(
43
+ fn=generate,
44
+ inputs=[
45
+ gr.Textbox(label="Prompt", placeholder="Describe the image you want to generate..."),
46
+ gr.Textbox(label="Negative Prompt (Optional)", placeholder="What you don't want in the image...")
47
+ ],
48
+ outputs=gr.Image(label="Generated Image"),
49
+ title="Rafayy AI Image Generator",
50
+ description="Generate unique images from text descriptions",
51
+ examples=[
52
+ ["A beautiful sunset over mountains", "blur, low quality"],
53
+ ["A futuristic city at night", "dark, blurry"],
54
+ ["A cute cat playing with yarn", "ugly, distorted"]
55
+ ]
56
+ )
57
+
58
+ # Launch the app
59
+ if __name__ == "__main__":
60
+ demo.launch()