|
import streamlit as st |
|
import requests |
|
from PIL import Image |
|
import numpy as np |
|
import io |
|
|
|
|
|
def apply_deepfake(image): |
|
|
|
image_bytes = io.BytesIO() |
|
image.save(image_bytes, format='JPEG') |
|
image_bytes = image_bytes.getvalue() |
|
|
|
|
|
api_url = "https://api-inference.huggingface.co/models/spaces/dalle-mini/dalle-mini" |
|
headers = {"Authorization": "Bearer YOUR_HUGGING_FACE_API_TOKEN"} |
|
response = requests.post(api_url, headers=headers, files={"file": image_bytes}) |
|
|
|
|
|
response_image = Image.open(io.BytesIO(response.content)) |
|
return response_image |
|
|
|
st.title("Image Processing MVP") |
|
|
|
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"]) |
|
|
|
if uploaded_file is not None: |
|
image = Image.open(uploaded_file) |
|
st.image(image, caption='Uploaded Image.', use_column_width=True) |
|
st.write("") |
|
st.write("Processing...") |
|
|
|
action = st.radio("Choose an action:", ('A', 'B', 'Deepfake')) |
|
|
|
if action == 'A': |
|
|
|
st.image(image, caption='Original Image.', use_column_width=True) |
|
elif action == 'B': |
|
|
|
image_np = np.array(image) |
|
noise = np.random.normal(0, 25, image_np.shape).astype(np.uint8) |
|
noisy_image = cv2.add(image_np, noise) |
|
st.image(noisy_image, caption='Image with Noise.', use_column_width=True) |
|
elif action == 'Deepfake': |
|
|
|
deepfake_image = apply_deepfake(image) |
|
st.image(deepfake_image, caption='Deepfake Image.', use_column_width=True) |
|
|