File size: 2,127 Bytes
650a2dc
dd0006c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
650a2dc
 
dd0006c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
650a2dc
 
 
 
dd0006c
 
 
 
 
650a2dc
dd0006c
 
 
 
650a2dc
dd0006c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import gradio as gr
from huggingface_hub import InferenceClient
from PIL import Image
import io
import os

API_KEY = os.getenv("HF_API_TOKEN")
MODEL_NAME = "stabilityai/stable-diffusion-3.5-large"

client = InferenceClient(api_key=API_KEY)

def generate_image(prompt):
    """Generate an image from a text prompt using Hugging Face API."""
    try:
        image = client.text_to_image(prompt, model=MODEL_NAME)
        img_byte_array = io.BytesIO()
        image.save(img_byte_array, format="PNG")
        img_byte_array.seek(0)
        return image
    except Exception as e:
        return f"Error generating image: {e}"

css = """
body {
    background: linear-gradient(135deg, #121212, #1e1e2e);
    color: white;
    font-family: 'Poppins', sans-serif;
    text-align: center;
}
.gradio-container {
    background: rgba(30, 30, 46, 0.9);
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    margin: auto;
}
button {
    background: linear-gradient(135deg, #ff416c, #ff4b4b);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 18px;
    padding: 12px;
    transition: 0.3s;
}
button:hover {
    background: linear-gradient(135deg, #ff4b4b, #ff416c);
    transform: scale(1.05);
}
h1, h2, h3, p, label {
    color: white !important;
}
input, textarea {
    background: #252537;
    color: white;
    border: 1px solid #444;
    padding: 10px;
    border-radius: 8px;
}
"""

with gr.Blocks(css=css) as demo:
    gr.Markdown(
        "<h2 style='color: white; font-size: 35px; font-weight: 600; margin-bottom: 100px;'>AI image Generator powered by Agents Valley 🤖</h2>"
    )
    gr.Markdown(
        "<h2 style='color: white; font-size: 15px; font-weight: 600; margin-bottom: 100px;'>Stable-Diffusion-3.5-Large</h2>"
    )
    prompt_input = gr.Textbox(label="Enter your prompt", value="A Dog is jumping..")
    output_image = gr.Image(label="Generated Image by Agents Valley")
    generate_button = gr.Button("Generate Image")
    generate_button.click(fn=generate_image, inputs=prompt_input, outputs=output_image)

demo.launch()