MUTSC commited on
Commit
2641d2d
1 Parent(s): 0a908a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -1
app.py CHANGED
@@ -1,3 +1,23 @@
1
  import gradio as gr
2
- gr.Interface.load("models/tensor-diffusion/melaura-v1-0").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
 
1
  import gradio as gr
2
+ from diffusers import StableDiffusionPipeline
3
+ from PIL import Image
4
+ import torch
5
+
6
+ # Load the Stable Diffusion model
7
+ model = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16)
8
+ model = model.to("cuda" if torch.cuda.is_available() else "cpu")
9
+
10
+ def generate_image(prompt):
11
+ # Generate image from the model
12
+ with torch.no_grad():
13
+ image = model(prompt).images[0]
14
+ # Convert to PIL Image to display in Gradio
15
+ image = Image.fromarray(image.numpy())
16
+ return image
17
+
18
+ # Create a Gradio interface
19
+ interface = gr.Interface(fn=generate_image, inputs='text', outputs='image')
20
+
21
+ # Launch the interface
22
+ interface.launch()
23