123LETSPLAY commited on
Commit
1343a16
1 Parent(s): 8127d65

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from diffusers import DiffusionPipeline
3
+ import gradio as gr
4
+
5
+ # Load the CogVideoX diffusion model
6
+ pipe = DiffusionPipeline.from_pretrained("THUDM/CogVideoX-5b", torch_dtype=torch.float16)
7
+ pipe.to("cuda") # Send the model to GPU if available
8
+
9
+ # Function to generate an image based on user prompt
10
+ def generate_image(prompt):
11
+ # Generate an image using the CogVideoX model
12
+ with torch.inference_mode():
13
+ image = pipe(prompt).images[0]
14
+ return image
15
+
16
+ # Set up the Gradio interface
17
+ with gr.Blocks() as demo:
18
+ gr.Markdown("# Image Generation using CogVideoX (THUDM/CogVideoX-5b)")
19
+
20
+ # Input for user to provide a text prompt
21
+ prompt_input = gr.Textbox(label="Enter Text Prompt", placeholder="e.g. 'Astronaut in a jungle, cold color palette, muted colors, detailed, 8k'", value="Astronaut in a jungle, cold color palette, muted colors, detailed, 8k")
22
+
23
+ # Output to display the generated image
24
+ output_image = gr.Image(label="Generated Image")
25
+
26
+ # Button to trigger image generation
27
+ generate_button = gr.Button("Generate Image")
28
+
29
+ # Link button click to image generation function
30
+ generate_button.click(fn=generate_image, inputs=prompt_input, outputs=output_image)
31
+
32
+ # Launch the Gradio app
33
+ demo.launch()