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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -1,6 +1,5 @@
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"
@@ -8,6 +7,7 @@ API_TOKEN = st.secrets["HF_API_TOKEN"] # You'll store this in the Hugging Face
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()
@@ -17,17 +17,17 @@ 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:
 
1
  import streamlit as st
2
  import requests
 
3
 
4
  # Hugging Face Inference API URL and Token
5
  API_URL = "https://api-inference.huggingface.co/models/Organika/sdxl-detector"
 
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()
 
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: