import streamlit as st import requests from PIL import Image import numpy as np import io # Function to apply deepfake-like transformation using an API def apply_deepfake(image): # Convert PIL image to bytes image_bytes = io.BytesIO() image.save(image_bytes, format='JPEG') image_bytes = image_bytes.getvalue() # Call the Hugging Face API 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}) # Convert response to image 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': # Just display the original image st.image(image, caption='Original Image.', use_column_width=True) elif action == 'B': # Add noise to the original image 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': # Apply deepfake transformation deepfake_image = apply_deepfake(image) st.image(deepfake_image, caption='Deepfake Image.', use_column_width=True)