goldenbrown commited on
Commit
c6a5000
·
verified ·
1 Parent(s): de38637

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ from io import BytesIO
4
+
5
+ # Hugging Face Inference API URL and Token
6
+ API_URL = "https://api-inference.huggingface.co/models/Organika/sdxl-detector"
7
+ API_TOKEN = st.secrets["HF_API_TOKEN"] # You'll store this in the Hugging Face secret
8
+
9
+ headers = {"Authorization": f"Bearer {API_TOKEN}"}
10
+
11
+ def query(image_bytes):
12
+ response = requests.post(API_URL, headers=headers, files={"inputs": image_bytes})
13
+ return response.json()
14
+
15
+ # Streamlit UI
16
+ st.title("AI Image Detector")
17
+
18
+ st.write("Upload an image, and we will check if it is AI-generated using the Hugging Face SDXL detector.")
19
+
20
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
21
+
22
+ if uploaded_file is not None:
23
+ # Display the uploaded image
24
+ image = uploaded_file.read()
25
+ st.image(image, caption="Uploaded Image", use_column_width=True)
26
+
27
+ st.write("Classifying...")
28
+
29
+ # Send the image to the model
30
+ result = query(image)
31
+
32
+ # Display the result
33
+ if "error" in result:
34
+ st.error(f"Error: {result['error']}")
35
+ else:
36
+ label = result[0]["label"]
37
+ if label == "AI-generated":
38
+ st.success("This image is AI-generated.")
39
+ else:
40
+ st.success("This image is not AI-generated.")