Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,9 +8,11 @@ API_TOKEN = st.secrets["HF_API_TOKEN"]
|
|
8 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
9 |
|
10 |
# Function to query the model
|
11 |
-
def query(
|
12 |
-
# Prepare the payload with binary image data
|
13 |
-
files = {
|
|
|
|
|
14 |
response = requests.post(API_URL, headers=headers, files=files)
|
15 |
return response.json()
|
16 |
|
@@ -28,11 +30,11 @@ if uploaded_file is not None:
|
|
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(
|
|
|
|
|
|
|
36 |
|
37 |
# Display the result
|
38 |
if "error" in result:
|
|
|
8 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
9 |
|
10 |
# Function to query the model
|
11 |
+
def query(image):
|
12 |
+
# Prepare the payload with binary image data and filename
|
13 |
+
files = {
|
14 |
+
"inputs": (image.name, image, "image/png" if image.name.endswith(".png") else "image/jpeg")
|
15 |
+
}
|
16 |
response = requests.post(API_URL, headers=headers, files=files)
|
17 |
return response.json()
|
18 |
|
|
|
30 |
|
31 |
st.write("Classifying...")
|
32 |
|
|
|
|
|
|
|
33 |
# Send the image to the model
|
34 |
+
result = query(uploaded_file)
|
35 |
+
|
36 |
+
# Debugging: Display the raw result from the Hugging Face API
|
37 |
+
st.write(result) # This will display the full API response for debugging
|
38 |
|
39 |
# Display the result
|
40 |
if "error" in result:
|