minhwai commited on
Commit
9af7098
·
verified ·
1 Parent(s): c483521

Update app.py

Browse files

"디퓨전 모델로 도입"

Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -1,24 +1,27 @@
1
  import streamlit as st
2
- import requests
 
3
  from PIL import Image
4
  import numpy as np
5
  import io
 
6
 
7
- # Function to apply deepfake-like transformation using an API
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
- # Call the Hugging Face API
15
- api_url = "https://api-inference.huggingface.co/models/spaces/dalle-mini/dalle-mini"
16
- headers = {"Authorization": "Bearer YOUR_HUGGING_FACE_API_TOKEN"}
17
- response = requests.post(api_url, headers=headers, files={"file": image_bytes})
18
-
19
- # Convert response to image
20
- response_image = Image.open(io.BytesIO(response.content))
21
- return response_image
 
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