Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,50 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
with gr.Blocks(
|
| 2 |
-
theme=gr.themes.Soft(
|
| 3 |
-
|
| 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 |
-
|
| 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 |
-
|
| 37 |
-
|
| 38 |
-
height = gr.Slider(256, 1024, value=768, step=64, label="π Height")
|
| 39 |
|
| 40 |
-
|
| 41 |
-
generate_btn = gr.Button("π Generate Image", variant="primary")
|
| 42 |
-
clear_btn = gr.Button("π§Ή Clear")
|
| 43 |
|
| 44 |
-
|
| 45 |
-
status = gr.Textbox(
|
| 46 |
|
| 47 |
-
|
| 48 |
|
| 49 |
-
|
| 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()
|
|
|