goldenbrown commited on
Commit
fd5266d
·
verified ·
1 Parent(s): 5fb91fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -3,13 +3,15 @@ import requests
3
 
4
  # Hugging Face Inference API URL and Token
5
  API_URL = "https://api-inference.huggingface.co/models/Organika/sdxl-detector"
6
- API_TOKEN = st.secrets["HF_API_TOKEN"] # You'll store this in the Hugging Face secret
7
 
8
  headers = {"Authorization": f"Bearer {API_TOKEN}"}
9
 
10
  # Function to query the model
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
@@ -17,18 +19,21 @@ 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
- # File uploader for user to upload image
21
  uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
22
 
23
  if uploaded_file is not None:
24
  # Display the uploaded image
25
  st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
26
-
27
  st.write("Classifying...")
28
-
 
 
 
29
  # Send the image to the model
30
- result = query(uploaded_file) # Use the file object directly
31
-
32
  # Display the result
33
  if "error" in result:
34
  st.error(f"Error: {result['error']}")
 
3
 
4
  # Hugging Face Inference API URL and Token
5
  API_URL = "https://api-inference.huggingface.co/models/Organika/sdxl-detector"
6
+ API_TOKEN = st.secrets["HF_API_TOKEN"]
7
 
8
  headers = {"Authorization": f"Bearer {API_TOKEN}"}
9
 
10
  # Function to query the model
11
  def query(image_bytes):
12
+ # Prepare the payload with binary image data
13
+ files = {"inputs": image_bytes}
14
+ response = requests.post(API_URL, headers=headers, files=files)
15
  return response.json()
16
 
17
  # Streamlit UI
 
19
 
20
  st.write("Upload an image, and we will check if it is AI-generated using the Hugging Face SDXL detector.")
21
 
22
+ # File uploader for the user to upload an image
23
  uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
24
 
25
  if uploaded_file is not None:
26
  # Display the uploaded image
27
  st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
28
+
29
  st.write("Classifying...")
30
+
31
+ # Read the uploaded file as bytes
32
+ image_bytes = uploaded_file.read() # Read the file as bytes
33
+
34
  # Send the image to the model
35
+ result = query(image_bytes)
36
+
37
  # Display the result
38
  if "error" in result:
39
  st.error(f"Error: {result['error']}")