|
1 | 1 | import gradio as gr
|
2 | 2 | import lightning as L
|
| 3 | +from lightning.app.storage import Drive |
3 | 4 | from lightning.app.components.serve import ServeGradio
|
4 | 5 |
|
5 | 6 | class MasterpieceCreator(ServeGradio):
|
6 |
| - inputs = gr.inputs.Textbox(label="print your prompt here") |
| 7 | + inputs = [gr.inputs.Textbox(label="print your prompt here"), gr.inputs.Number(default=250, label="number of steps")] |
7 | 8 | outputs = gr.outputs.Image(type="auto", label="Your masterpiece is ready")
|
8 | 9 | enable_queue = True
|
9 | 10 |
|
10 |
| - def predict(self, prompt): |
| 11 | + def __init__(self, *args, **kwargs): |
| 12 | + super().__init__(*args, **kwargs) |
| 13 | + self.drive_1 = Drive("lit://drive_1") |
| 14 | + |
| 15 | + def predict(self, prompt, number_of_steps): |
11 | 16 | results = self.model.create(
|
12 | 17 | text_prompts=prompt,
|
13 |
| - width_height=[512, 512], |
| 18 | + width_height=[512, 448], |
14 | 19 | n_batches=1,
|
| 20 | + steps=number_of_steps, |
| 21 | + diffusion_model="watercolordiffusion", |
| 22 | + clip_models=["ViT-B-32::openai"], |
| 23 | + clip_guidance_scale=40000, |
15 | 24 | )
|
| 25 | + |
| 26 | + file_name = f"./img2.png" |
16 | 27 | result = results[0]
|
17 | 28 | result.load_uri_to_image_tensor()
|
| 29 | + result.save_image_tensor_to_file(file_name) |
| 30 | + self.drive_1.put(file_name) |
18 | 31 | return result.tensor
|
19 | 32 |
|
20 | 33 | def build_model(self):
|
|
0 commit comments