RanM commited on
Commit
f466dd9
·
verified ·
1 Parent(s): b54e448

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import DiffusionPipeline
4
+
5
+ def load_amused_model():
6
+ return DiffusionPipeline.from_pretrained("amused/amused-256")
7
+
8
+ # Generate image from prompt using AmusedPipeline
9
+ def generate_image(prompt):
10
+ try:
11
+ pipe = load_amused_model()
12
+ generator = torch.Generator().manual_seed(8) # Create a generator for reproducibility
13
+ image = pipe(prompt, generator=generator).images[0] # Generate image from prompt
14
+ return image, None
15
+ except Exception as e:
16
+ return None, str(e)
17
+
18
+ def inference(prompt):
19
+ image, error = generate_image(prompt)
20
+ if error:
21
+ return "Error: " + error
22
+ return image
23
+
24
+ gradio_interface = gr.Interface(
25
+ fn=inference,
26
+ inputs="text",
27
+ outputs="image"
28
+ )
29
+
30
+ if __name__ == "__main__":
31
+ gradio_interface.launch()