Shangkhonil commited on
Commit
9152027
·
verified ·
1 Parent(s): 68dbd4d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from diffusers import DiffusionPipeline
3
+ import torch
4
+
5
+ # Load the Shap-E pipeline (adjust the model path if needed)
6
+ pipeline = DiffusionPipeline.from_pretrained("openai/shap-e", torch_dtype=torch.float16)
7
+ pipeline = pipeline.to("cuda" if torch.cuda.is_available() else "cpu")
8
+
9
+ def generate_image(prompt):
10
+ # Generate an image based on the prompt using the pipeline
11
+ output = pipeline(prompt)
12
+ # Assuming that the output has a `images` field with a list of images
13
+ return output.images[0]
14
+
15
+ # Create Gradio interface
16
+ title = "Shap-E Model Demo"
17
+ description = "Generate images from text prompts using the Shap-E diffusion model."
18
+
19
+ # Set up the interface
20
+ interface = gr.Interface(
21
+ fn=generate_image,
22
+ inputs=gr.Textbox(label="Prompt"),
23
+ outputs=gr.Image(label="Generated Image"),
24
+ title=title,
25
+ description=description,
26
+ )
27
+
28
+ # Launch the Gradio app
29
+ if __name__ == "__main__":
30
+ interface.launch()