SNA-AI commited on
Commit
0000954
Β·
verified Β·
1 Parent(s): cd3ab0c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -42
app.py CHANGED
@@ -1,50 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  with gr.Blocks(
2
- theme=gr.themes.Soft(
3
- primary_hue="blue",
4
- secondary_hue="indigo",
5
- neutral_hue="gray"
6
- ),
7
- css="""
8
- body {
9
- background-color: #f4f7ff !important;
10
- }
11
-
12
- .gradio-container {
13
- background-color: #f4f7ff !important;
14
- }
15
-
16
- button {
17
- border-radius: 10px !important;
18
- }
19
- """
20
  ) as app:
21
 
22
- gr.Markdown(
23
- """
24
- # 🎨 AI Text β†’ Image Generator
25
- ### ✨ Create beautiful AI images instantly
26
- """
27
- )
28
-
29
- with gr.Row():
30
- prompt = gr.Textbox(
31
- label="✍️ Enter Prompt",
32
- placeholder="A futuristic city at sunset, ultra detailed, cinematic lighting",
33
- lines=3
34
- )
35
 
36
- with gr.Row():
37
- width = gr.Slider(256, 1024, value=768, step=64, label="πŸ“ Width")
38
- height = gr.Slider(256, 1024, value=768, step=64, label="πŸ“ Height")
39
 
40
- with gr.Row():
41
- generate_btn = gr.Button("πŸš€ Generate Image", variant="primary")
42
- clear_btn = gr.Button("🧹 Clear")
43
 
44
- output_image = gr.Image(label="πŸ–ΌοΈ Generated Image", type="pil")
45
- status = gr.Textbox(label="πŸ“’ Status")
46
 
47
- generate_btn.click(generate_image, [prompt, width, height], [output_image, status])
48
 
49
- clear_btn.click(lambda: ("", 768, 768, None, ""), None,
50
- [prompt, width, height, output_image, status])
 
1
+ import gradio as gr
2
+ import os
3
+ from huggingface_hub import InferenceClient
4
+
5
+ # πŸ”‘ token
6
+ HF_TOKEN = os.getenv("image")
7
+
8
+ client = InferenceClient(
9
+ model="stabilityai/stable-diffusion-xl-base-1.0",
10
+ token=HF_TOKEN
11
+ )
12
+
13
+ def generate_image(prompt, width, height):
14
+ if not prompt.strip():
15
+ return None, "⚠️ Enter prompt"
16
+
17
+ try:
18
+ image = client.text_to_image(
19
+ prompt,
20
+ width=int(width),
21
+ height=int(height)
22
+ )
23
+ return image, "βœ… Image generated"
24
+
25
+ except Exception as e:
26
+ return None, f"❌ Error: {str(e)}"
27
+
28
+
29
+ # 🎨 UI (LIGHT + MODERN)
30
  with gr.Blocks(
31
+ theme=gr.themes.Soft(primary_hue="blue"),
32
+ css="body {background-color:#f4f7ff !important;}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  ) as app:
34
 
35
+ gr.Markdown("# 🎨 AI Text β†’ Image Generator")
36
+
37
+ prompt = gr.Textbox(label="Prompt")
 
 
 
 
 
 
 
 
 
 
38
 
39
+ width = gr.Slider(256, 1024, value=768, step=64, label="Width")
40
+ height = gr.Slider(256, 1024, value=768, step=64, label="Height")
 
41
 
42
+ btn = gr.Button("Generate", variant="primary")
 
 
43
 
44
+ img = gr.Image(type="pil")
45
+ status = gr.Textbox()
46
 
47
+ btn.click(generate_image, [prompt, width, height], [img, status])
48
 
49
+ app.launch()