text-img / app.py
Ahsan-Raza's picture
Rename Text to img.py to app.py
4bdefee verified
Raw History Blame Contribute Delete
1.35 kB
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)