Spaces:
Sleeping
Sleeping
Commit
·
5db71ea
1
Parent(s):
f9df164
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import io
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import json
|
| 6 |
+
import os
|
| 7 |
+
import shutil
|
| 8 |
+
import logging
|
| 9 |
+
import math
|
| 10 |
+
from tqdm import tqdm
|
| 11 |
+
import time
|
| 12 |
+
from diffusers import DiffusionPipeline
|
| 13 |
+
|
| 14 |
+
def run_lora(base_model, lora, prompt, neg_prompt, progress=gr.Progress(track_tqdm=True)):
|
| 15 |
+
print(f"Inside run_lora, base_model: {base_model}, lora: {lora.name}, prompt: {prompt}, neg_prompt: {neg_prompt}")
|
| 16 |
+
|
| 17 |
+
base_repo = None
|
| 18 |
+
if base_model == "v1-5":
|
| 19 |
+
base_repo = "runwayml/stable-diffusion-v1-5"
|
| 20 |
+
elif base_model == "v2-1":
|
| 21 |
+
base_repo = "stabilityai/stable-diffusion-2-1"
|
| 22 |
+
elif base_model == "v2":
|
| 23 |
+
base_repo = "stabilityai/stable-diffusion-2"
|
| 24 |
+
|
| 25 |
+
print(f"base_repo: {base_repo}")
|
| 26 |
+
|
| 27 |
+
pipeline = DiffusionPipeline.from_pretrained(base_repo)
|
| 28 |
+
pipeline.load_lora_weights(lora.name)
|
| 29 |
+
print(pipeline)
|
| 30 |
+
|
| 31 |
+
image = pipeline(prompt, negative_prompt = neg_prompt).images[0]
|
| 32 |
+
return image
|
| 33 |
+
|
| 34 |
+
demo = gr.Interface(
|
| 35 |
+
run_lora,
|
| 36 |
+
[
|
| 37 |
+
gr.Dropdown(
|
| 38 |
+
["v1-5", "v2", "v2-1"], label="Base Model", info="Stable Diffusion Base Model."
|
| 39 |
+
),
|
| 40 |
+
gr.File(file_count="single", file_types=[".safetensors"]),
|
| 41 |
+
gr.Textbox(label="Prompt", show_label=False, lines=1, max_lines=1, placeholder="Type a prompt after selecting a LoRA"),
|
| 42 |
+
gr.Textbox(label="Negative Prompt", show_label=False, lines=1, max_lines=1, placeholder="Type negative prompt here.")
|
| 43 |
+
],
|
| 44 |
+
"image",
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
demo.launch()
|