File size: 1,558 Bytes
c6a5000
 
 
 
 
fd5266d
c6a5000
 
 
5fb91fa
1805d98
 
 
 
 
fd5266d
c6a5000
 
 
 
 
 
 
fd5266d
c6a5000
 
 
 
5fb91fa
fd5266d
c6a5000
fd5266d
c6a5000
1805d98
 
 
 
fd5266d
c6a5000
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import streamlit as st
import requests

# Hugging Face Inference API URL and Token
API_URL = "https://api-inference.huggingface.co/models/Organika/sdxl-detector"
API_TOKEN = st.secrets["HF_API_TOKEN"]

headers = {"Authorization": f"Bearer {API_TOKEN}"}

# Function to query the model
def query(image):
    # Prepare the payload with binary image data and filename
    files = {
        "inputs": (image.name, image, "image/png" if image.name.endswith(".png") else "image/jpeg")
    }
    response = requests.post(API_URL, headers=headers, files=files)
    return response.json()

# Streamlit UI
st.title("AI Image Detector")

st.write("Upload an image, and we will check if it is AI-generated using the Hugging Face SDXL detector.")

# File uploader for the user to upload an image
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])

if uploaded_file is not None:
    # Display the uploaded image
    st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)

    st.write("Classifying...")

    # Send the image to the model
    result = query(uploaded_file)

    # Debugging: Display the raw result from the Hugging Face API
    st.write(result)  # This will display the full API response for debugging

    # Display the result
    if "error" in result:
        st.error(f"Error: {result['error']}")
    else:
        label = result[0]["label"]
        if label == "AI-generated":
            st.success("This image is AI-generated.")
        else:
            st.success("This image is not AI-generated.")