Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import gradio as gr
|
3 |
+
from diffusers import DiffusionPipeline
|
4 |
+
|
5 |
+
# Load the pre-trained model from Hugging Face
|
6 |
+
pipe = DiffusionPipeline.from_pretrained("alexx-ai/GBL2", torch_dtype=torch.float16)
|
7 |
+
|
8 |
+
# Move the model to GPU if available
|
9 |
+
pipe.to("cuda")
|
10 |
+
|
11 |
+
# Function to generate an image based on the input prompt
|
12 |
+
def generate_image(prompt):
|
13 |
+
# Generate the image using the model's pipeline
|
14 |
+
image = pipe(prompt).images[0]
|
15 |
+
return image
|
16 |
+
|
17 |
+
# Create the Gradio interface for text-to-image generation
|
18 |
+
with gr.Blocks() as demo:
|
19 |
+
gr.Markdown("### Text to Image Generator using GBL2")
|
20 |
+
|
21 |
+
# Input text box for the prompt
|
22 |
+
prompt_input = gr.Textbox(label="Enter your prompt", placeholder="Type something like 'A beautiful sunset in Ghibli style'")
|
23 |
+
|
24 |
+
# Output image display
|
25 |
+
image_output = gr.Image(label="Generated Image")
|
26 |
+
|
27 |
+
# Set up the button to trigger the image generation
|
28 |
+
prompt_input.submit(generate_image, inputs=prompt_input, outputs=image_output)
|
29 |
+
|
30 |
+
# Launch the Gradio app
|
31 |
+
demo.launch()
|