Spaces:
Runtime error
Runtime error
Commit
·
67c45b7
1
Parent(s):
cbb9cf1
Upload 3 files
Browse files- app.py +110 -0
- requirements.txt +12 -0
app.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from streamlit_drawable_canvas import st_canvas
|
| 3 |
+
from PIL import Image
|
| 4 |
+
from typing import Union
|
| 5 |
+
import random
|
| 6 |
+
import numpy as np
|
| 7 |
+
import os
|
| 8 |
+
import time
|
| 9 |
+
|
| 10 |
+
st.set_page_config(layout="wide")
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def create_edit_existing_image_tab():
|
| 14 |
+
st.write("# Edit existing image")
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
cols = st.columns(2)
|
| 18 |
+
with cols[0]:
|
| 19 |
+
image_source = st.file_uploader("Upload source image", type=["png", "jpg", "jpeg", "webp"], key="upload_source_edit_existing_image")
|
| 20 |
+
st.text_input("Source object", key="text_input_source_edit_existing_image")
|
| 21 |
+
st.image('content/dog.png')
|
| 22 |
+
with cols[1]:
|
| 23 |
+
image_target = st.file_uploader("Upload target image", type=["png", "jpg", "jpeg", "webp"], key="upload_target_edit_existing_image")
|
| 24 |
+
st.text_input("Target object", key="text_input_target_edit_existing_image")
|
| 25 |
+
st.image('content/cat-sofa.png')
|
| 26 |
+
|
| 27 |
+
st.text_input("Prompt", key="text_input_prompt_edit_existing_image")
|
| 28 |
+
st.text_input("Negative prompt", key="text_input_negative_prompt_edit_existing_image")
|
| 29 |
+
st.button("Generate", key="button_generate_edit_existing_image")
|
| 30 |
+
|
| 31 |
+
st.write("## Result")
|
| 32 |
+
st.image('content/cat-sofa.png')
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def create_edit_generated_image_tab():
|
| 36 |
+
st.write("# Edit generated image")
|
| 37 |
+
|
| 38 |
+
cols = st.columns(2)
|
| 39 |
+
with cols[0]:
|
| 40 |
+
image_source = st.file_uploader("Upload source image", type=["png", "jpg", "jpeg", "webp"], key="upload_source_edit_generated_image")
|
| 41 |
+
st.text_input("Target object", key="text_input_source_edit_generated_image")
|
| 42 |
+
st.text_input("Prompt", key="text_input_prompt_edit_generated_image")
|
| 43 |
+
st.text_input("Negative prompt", key="text_input_negative_prompt_edit_generated_image")
|
| 44 |
+
if image_source:
|
| 45 |
+
st.button("Generate", key="button_generate_edit_generated_image")
|
| 46 |
+
with cols[1]:
|
| 47 |
+
st.image('content/dog.png')
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
st.write("## Result")
|
| 51 |
+
cols_result = st.columns(2)
|
| 52 |
+
with cols_result[0]:
|
| 53 |
+
st.image('content/dog.png')
|
| 54 |
+
with cols_result[1]:
|
| 55 |
+
st.image('content/cat-sofa.png')
|
| 56 |
+
|
| 57 |
+
def create_zero_shot_generation_tab():
|
| 58 |
+
st.write("# Zero-shot generation")
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def create_zero_shot_stylization_tab():
|
| 62 |
+
st.write("# Zero-shot stylization")
|
| 63 |
+
|
| 64 |
+
def create_home_tab():
|
| 65 |
+
st.write("# Home of BLIP-Diffusion")
|
| 66 |
+
st.write("Welcome to the demo application of BLIP-Diffusion")
|
| 67 |
+
|
| 68 |
+
st.write("Project page is [here](https://dxli94.github.io/BLIP-Diffusion-website/.)")
|
| 69 |
+
st.write("Github page is [here](https://github.com/salesforce/LAVIS/tree/main/projects/blip-diffusion)")
|
| 70 |
+
st.write("Paper is [here](https://arxiv.org/abs/2305.14720)")
|
| 71 |
+
|
| 72 |
+
st.image('content/teaser-website.png')
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def main():
|
| 76 |
+
|
| 77 |
+
with st.sidebar:
|
| 78 |
+
st.title("Navigation")
|
| 79 |
+
st.slider("Guidance scale", 0.0, 20.0, 7.5, 0.1)
|
| 80 |
+
st.slider("Inference steps", 5, 40, 20, 1)
|
| 81 |
+
st.number_input("Seed", 0, 100000, 0, 1)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
tab_names = ["Home", "Edit existing image", "Edit generated image", "Zero-shot generation", "Zero-shot stylization"]
|
| 85 |
+
|
| 86 |
+
(home_tab,
|
| 87 |
+
edit_existing_image_tab,
|
| 88 |
+
edit_generated_image_tab,
|
| 89 |
+
zero_shot_generation_tab,
|
| 90 |
+
zero_shot_stylization_tab) = st.tabs(tab_names)
|
| 91 |
+
|
| 92 |
+
with home_tab:
|
| 93 |
+
create_home_tab()
|
| 94 |
+
|
| 95 |
+
with edit_existing_image_tab:
|
| 96 |
+
create_edit_existing_image_tab()
|
| 97 |
+
|
| 98 |
+
with edit_generated_image_tab:
|
| 99 |
+
create_edit_generated_image_tab()
|
| 100 |
+
|
| 101 |
+
with zero_shot_generation_tab:
|
| 102 |
+
create_zero_shot_generation_tab()
|
| 103 |
+
|
| 104 |
+
with zero_shot_stylization_tab:
|
| 105 |
+
create_zero_shot_stylization_tab()
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
if __name__ == "__main__":
|
| 109 |
+
main()
|
| 110 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
streamlit-drawable-canvas==0.9.0
|
| 3 |
+
# diffusers==0.15.0
|
| 4 |
+
# xformers==0.0.16
|
| 5 |
+
# transformers
|
| 6 |
+
# torchvision==0.14.1
|
| 7 |
+
# git+https://github.com/huggingface/accelerate.git
|
| 8 |
+
opencv-python-headless
|
| 9 |
+
scipy
|
| 10 |
+
# python-docx
|
| 11 |
+
extra-streamlit-components
|
| 12 |
+
# triton
|