Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,27 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
gr.load("models/K00B404/tiny_image_gen").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
#gr.load("models/K00B404/tiny_image_gen").launch()
|
4 |
+
|
5 |
+
# GenerativeApp.py
|
6 |
+
import os
|
7 |
+
import torch
|
8 |
+
from PIL import Image
|
9 |
+
from diffusers import StableDiffusionPipeline
|
10 |
+
from transformers import AutoTokenizer
|
11 |
+
|
12 |
+
def load_model():
|
13 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
14 |
+
model_path = "K00B404/tiny_image_gen"
|
15 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_path, revision='main', torch_dtype=torch.float16)
|
16 |
+
pipe = pipe.to(device)
|
17 |
+
return pipe
|
18 |
+
|
19 |
+
def generate_image(prompt):
|
20 |
+
pipe = load_model()
|
21 |
+
output = pipe(prompt, num_inference_steps=50, height=512, width=512)
|
22 |
+
image = output["samples"][0]
|
23 |
+
return Image.fromarray((image.transpose(1, 2, 0) * 255).detach().cpu().numpy().astype(np.uint8))
|
24 |
+
|
25 |
+
if __name__ == "__main__":
|
26 |
+
gradio_app = gr.Interface(generate_image, inputs="text", outputs="image")
|
27 |
+
gradio_app.launch()
|