Update app.py
Browse files"디퓨전 모델로 도입"
app.py
CHANGED
@@ -1,24 +1,27 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
|
|
3 |
from PIL import Image
|
4 |
import numpy as np
|
5 |
import io
|
|
|
6 |
|
7 |
-
# Function to apply deepfake-like transformation using
|
8 |
def apply_deepfake(image):
|
9 |
# Convert PIL image to bytes
|
10 |
image_bytes = io.BytesIO()
|
11 |
image.save(image_bytes, format='JPEG')
|
12 |
image_bytes = image_bytes.getvalue()
|
13 |
-
|
14 |
-
#
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
22 |
|
23 |
st.title("Image Processing MVP")
|
24 |
|
|
|
1 |
import streamlit as st
|
2 |
+
import torch
|
3 |
+
from diffusers import StableDiffusionPipeline
|
4 |
from PIL import Image
|
5 |
import numpy as np
|
6 |
import io
|
7 |
+
import requests
|
8 |
|
9 |
+
# Function to apply deepfake-like transformation using Stable Diffusion
|
10 |
def apply_deepfake(image):
|
11 |
# Convert PIL image to bytes
|
12 |
image_bytes = io.BytesIO()
|
13 |
image.save(image_bytes, format='JPEG')
|
14 |
image_bytes = image_bytes.getvalue()
|
15 |
+
|
16 |
+
# Initialize the Stable Diffusion pipeline
|
17 |
+
model_id = "CompVis/stable-diffusion-v1-4"
|
18 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
19 |
+
pipe = pipe.to("cuda")
|
20 |
+
|
21 |
+
prompt = "A person with a different face but same pose and background"
|
22 |
+
|
23 |
+
result = pipe(prompt, init_image=image, strength=0.75)
|
24 |
+
return result.images[0]
|
25 |
|
26 |
st.title("Image Processing MVP")
|
27 |
|