Update app.py
Browse files"λ₯νμ΄ν¬ λλλκ²"
app.py
CHANGED
@@ -1,57 +1,47 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
import numpy as np
|
4 |
from PIL import Image
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
image
|
9 |
-
|
10 |
-
|
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 |
-
#
|
23 |
-
|
24 |
-
|
|
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
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("
|
38 |
|
39 |
if uploaded_file is not None:
|
40 |
image = Image.open(uploaded_file)
|
41 |
-
st.image(image, caption='
|
42 |
st.write("")
|
43 |
st.write("Processing...")
|
44 |
|
45 |
-
|
46 |
-
image_np = np.array(image)
|
47 |
-
|
48 |
-
action = st.radio("Choose an action:", ('A', 'B'))
|
49 |
|
50 |
-
if action == '
|
51 |
-
#
|
52 |
-
|
53 |
-
|
54 |
-
elif action == 'λ°©μ΄λ μ¬μ§μ΄ λ₯νμ΄ν¬μ μ
λ ₯λ κ²½μ°':
|
55 |
# Add noise to the original image
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|