minhwai commited on
Commit
0f13455
β€’
1 Parent(s): 7334e19

Update app.py

Browse files

"λ”₯페이크 λŠλ‚Œλ‚˜κ²Œ"

Files changed (1) hide show
  1. app.py +32 -42
app.py CHANGED
@@ -1,57 +1,47 @@
1
  import streamlit as st
2
- import cv2
3
- import numpy as np
4
  from PIL import Image
 
 
5
 
6
- def change_hair_to_blonde(image):
7
- # Convert to OpenCV format
8
- image = np.array(image)
9
- # Convert the image to HSV color space
10
- hsv = cv2.cvtColor(image, cv2.COLOR_RGB2HSV)
11
-
12
- # Define the range for hair color (dark colors)
13
- lower_hair = np.array([0, 0, 0])
14
- upper_hair = np.array([180, 255, 30])
15
-
16
- # Create a mask for hair
17
- mask = cv2.inRange(hsv, lower_hair, upper_hair)
18
-
19
- # Change hair color to blonde (light yellow)
20
- hsv[mask > 0] = (30, 255, 200)
21
 
22
- # Convert back to RGB color space
23
- image_blonde = cv2.cvtColor(hsv, cv2.COLOR_HSV2RGB)
24
- return image_blonde
 
25
 
26
- def add_noise(image):
27
- # Convert to OpenCV format
28
- image_np = np.array(image)
29
- # Generate random noise
30
- noise = np.random.normal(0, 25, image_np.shape).astype(np.uint8)
31
- # Add noise to the image
32
- noisy_image = cv2.add(image_np, noise)
33
- return noisy_image
34
 
35
- st.title("λ”₯페이크 사전 방지 ν•„ν„° μ”Œμš°κΈ°")
36
 
37
- uploaded_file = st.file_uploader("ν•„ν„°λ₯Ό μ”ŒμšΈ 이미지λ₯Ό μ—…λ‘œλ“œν•˜μ„Έμš”...", type=["jpg", "png", "jpeg"])
38
 
39
  if uploaded_file is not None:
40
  image = Image.open(uploaded_file)
41
- st.image(image, caption='λ…Έμ΄μ¦ˆ μ”Œμš΄ 이미지', use_column_width=True)
42
  st.write("")
43
  st.write("Processing...")
44
 
45
- # Save the original image as a numpy array
46
- image_np = np.array(image)
47
-
48
- action = st.radio("Choose an action:", ('A', 'B'))
49
 
50
- if action == '원본 사진이 λ”₯νŽ˜μ΄ν¬μ— μž…λ ₯된 경우':
51
- # Change hair color to blonde
52
- processed_image = change_hair_to_blonde(image)
53
- st.image(processed_image, caption='원본 사진이 λ”₯νŽ˜μ΄ν¬μ— μž…λ ₯된 경우', use_column_width=True)
54
- elif action == 'λ°©μ–΄λœ 사진이 λ”₯νŽ˜μ΄ν¬μ— μž…λ ₯된 경우':
55
  # Add noise to the original image
56
- processed_image = add_noise(image_np)
57
- st.image(processed_image, caption='λ°©μ–΄λœ 사진이 λ”₯νŽ˜μ΄ν¬μ— μž…λ ₯된 경우', use_column_width=True)
 
 
 
 
 
 
 
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
 
25
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
26
 
27
  if uploaded_file is not None:
28
  image = Image.open(uploaded_file)
29
+ st.image(image, caption='Uploaded Image.', use_column_width=True)
30
  st.write("")
31
  st.write("Processing...")
32
 
33
+ action = st.radio("Choose an action:", ('A', 'B', 'Deepfake'))
 
 
 
34
 
35
+ if action == 'A':
36
+ # Just display the original image
37
+ st.image(image, caption='Original Image.', use_column_width=True)
38
+ elif action == 'B':
 
39
  # Add noise to the original image
40
+ image_np = np.array(image)
41
+ noise = np.random.normal(0, 25, image_np.shape).astype(np.uint8)
42
+ noisy_image = cv2.add(image_np, noise)
43
+ st.image(noisy_image, caption='Image with Noise.', use_column_width=True)
44
+ elif action == 'Deepfake':
45
+ # Apply deepfake transformation
46
+ deepfake_image = apply_deepfake(image)
47
+ st.image(deepfake_image, caption='Deepfake Image.', use_column_width=True)