Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from diffusers import AutoPipelineForText2Image
|
4 |
+
|
5 |
+
# Load the model
|
6 |
+
pipe = AutoPipelineForText2Image.from_pretrained("kandinsky-community/kandinsky-3", variant="fp16", torch_dtype=torch.float16)
|
7 |
+
pipe.enable_model_cpu_offload()
|
8 |
+
|
9 |
+
# Define the input and output functions
|
10 |
+
def text_to_image(prompt):
|
11 |
+
generator = torch.Generator(device="cpu").manual_seed(0)
|
12 |
+
image = pipe(prompt, num_inference_steps=25, generator=generator).images[0]
|
13 |
+
return image
|
14 |
+
|
15 |
+
# Create a placeholder
|
16 |
+
placeholder = "A photograph of the inside of a subway train. There are raccoons sitting on the seats. One of them is reading a newspaper. The window shows the city in the background."
|
17 |
+
|
18 |
+
# Create the Gradio interface
|
19 |
+
title = "Kandinsky 3.0"
|
20 |
+
description = "This model generates an image based on a given text prompt."
|
21 |
+
how_to_use = "Input a description of the image you want to generate, for example: 'A forest with a river and a bridge under the moonlight.'"
|
22 |
+
examples = [["A dark alley with flickering streetlights and a mysterious figure lurking in the shadows"],
|
23 |
+
["A futuristic cityscape with neon lights and flying cars"]]
|
24 |
+
|
25 |
+
gr.Interface(fn=text_to_image, inputs=gr.Textbox(placeholder=placeholder), outputs=gr.Image()).launch()
|