File size: 1,346 Bytes
47129c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from diffusers import StableDiffusionPipeline
import torch

# Load the model
model_id = "CompVis/stable-diffusion-v1-4"
pipe = StableDiffusionPipeline.from_pretrained(model_id)
pipe.to("cuda")  # or "cpu" if you don't have GPU

# Image generation function
def generate_image(prompt):
    image = pipe(prompt).images[0]
    return image

# Custom CSS for beautifying the interface
custom_css = """
footer {
    text-align: center;
    font-size: 16px;
    font-weight: bold;
    color: #4CAF50;
}
.gradio-container {
    background-color: #f5f5f5;
    border-radius: 15px;
    padding: 20px;
}
input, textarea {
    border: 2px solid #4CAF50;
    border-radius: 10px;
    padding: 10px;
}
"""

# Interface definition with a footer
with gr.Blocks(css=custom_css) as interface:
    gr.Markdown("# AI Image Generator")
    gr.Markdown("**Enter a prompt to generate an image**")

    # Input and Output
    with gr.Row():
        text_input = gr.Textbox(label="Prompt", placeholder="Enter text here")
        image_output = gr.Image(label="Generated Image")

    # Submit button
    submit_button = gr.Button("Generate")
    submit_button.click(generate_image, inputs=text_input, outputs=image_output)

    # Footer section
    gr.HTML('<footer>Powered by Ahsan TECH</footer>')

# Launch the interface
interface.launch(share=True)