AgentNLP commited on
Commit
a28d291
·
verified ·
1 Parent(s): 0fdccab

Create app,py

Browse files
Files changed (1) hide show
  1. app,py +73 -0
app,py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import StableDiffusionPipeline
4
+
5
+ MODEL_ID = "runwayml/stable-diffusion-v1-5"
6
+
7
+ pipe = StableDiffusionPipeline.from_pretrained(
8
+ MODEL_ID,
9
+ torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
10
+ )
11
+
12
+ if torch.cuda.is_available():
13
+ pipe = pipe.to("cuda")
14
+
15
+ STYLES = {
16
+ "None": "",
17
+ "Cinematic": "cinematic lighting, dramatic, ultra detailed",
18
+ "Anime": "anime style, vibrant colors, sharp lines",
19
+ "Oil Painting": "oil painting, textured brush strokes",
20
+ "Cyberpunk": "cyberpunk, neon lights, futuristic",
21
+ "Fantasy Art": "fantasy art, magical, epic composition"
22
+ }
23
+
24
+ def generate(prompt, style, steps, guidance):
25
+ full_prompt = prompt
26
+ if STYLES[style]:
27
+ full_prompt = f"{prompt}, {STYLES[style]}"
28
+
29
+ image = pipe(
30
+ prompt=full_prompt,
31
+ num_inference_steps=steps,
32
+ guidance_scale=guidance
33
+ ).images[0]
34
+
35
+ return image
36
+
37
+ with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple")) as demo:
38
+ gr.Markdown(
39
+ """
40
+ # ✨ Instruct Image
41
+ Create images from text instructions using AI.
42
+ """
43
+ )
44
+
45
+ with gr.Row():
46
+ with gr.Column(scale=1):
47
+ prompt = gr.Textbox(
48
+ label="Instruction",
49
+ placeholder="A futuristic city at night with glowing neon lights",
50
+ lines=3
51
+ )
52
+
53
+ style = gr.Dropdown(
54
+ choices=list(STYLES.keys()),
55
+ value="None",
56
+ label="Style"
57
+ )
58
+
59
+ steps = gr.Slider(15, 50, value=30, step=1, label="Steps")
60
+ guidance = gr.Slider(1, 15, value=7.5, step=0.5, label="Guidance")
61
+
62
+ generate_btn = gr.Button("✨ Generate Image", variant="primary")
63
+
64
+ with gr.Column(scale=1):
65
+ output = gr.Image(label="Result", height=512)
66
+
67
+ generate_btn.click(
68
+ fn=generate,
69
+ inputs=[prompt, style, steps, guidance],
70
+ outputs=output
71
+ )
72
+
73
+ gr.Markdow