Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ from PIL import Image
|
|
| 3 |
import gradio as gr
|
| 4 |
import tempfile
|
| 5 |
import os
|
| 6 |
-
|
| 7 |
|
| 8 |
# Get Hugging Face Token from environment variables
|
| 9 |
# This token is crucial for accessing private spaces
|
|
@@ -29,30 +29,21 @@ def call_private_api(pil_img: Image.Image):
|
|
| 29 |
Image.Image: The processed image with detected damages from the private API.
|
| 30 |
"""
|
| 31 |
# Save the user-uploaded image to a temporary JPEG file.
|
| 32 |
-
# This is necessary
|
| 33 |
file_path = None # Initialize file_path
|
| 34 |
try:
|
| 35 |
with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as tmp:
|
| 36 |
pil_img.convert("RGB").save(tmp, "JPEG", quality=95)
|
| 37 |
file_path = tmp.name # Store the path to the temporary file
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
# Encode the image bytes to a Base64 string
|
| 44 |
-
# Gradio typically expects Base64 strings to be prefixed with 'data:image/jpeg;base64,'
|
| 45 |
-
# for images, or just the Base64 string, depending on the version/component.
|
| 46 |
-
# Let's try with the prefix first, as it's more explicit.
|
| 47 |
-
base64_image_string = "data:image/jpeg;base64," + base64.b64encode(image_bytes).decode('utf-8')
|
| 48 |
|
| 49 |
-
#
|
| 50 |
-
|
| 51 |
-
print(f"DEBUG: Start of base64_image_string: {base64_image_string[:50]}...")
|
| 52 |
-
|
| 53 |
-
# Pass the Base64 string directly as the image input
|
| 54 |
result_path = client.predict(
|
| 55 |
-
image=
|
| 56 |
api_name="/predict",
|
| 57 |
)
|
| 58 |
|
|
@@ -69,6 +60,7 @@ def call_private_api(pil_img: Image.Image):
|
|
| 69 |
if file_path and os.path.exists(file_path):
|
| 70 |
os.remove(file_path)
|
| 71 |
|
|
|
|
| 72 |
|
| 73 |
|
| 74 |
# 3️⃣ Set up the Gradio interface for the public space
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import tempfile
|
| 5 |
import os
|
| 6 |
+
|
| 7 |
|
| 8 |
# Get Hugging Face Token from environment variables
|
| 9 |
# This token is crucial for accessing private spaces
|
|
|
|
| 29 |
Image.Image: The processed image with detected damages from the private API.
|
| 30 |
"""
|
| 31 |
# Save the user-uploaded image to a temporary JPEG file.
|
| 32 |
+
# This is necessary because gradio_client expects a file path for image inputs.
|
| 33 |
file_path = None # Initialize file_path
|
| 34 |
try:
|
| 35 |
with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as tmp:
|
| 36 |
pil_img.convert("RGB").save(tmp, "JPEG", quality=95)
|
| 37 |
file_path = tmp.name # Store the path to the temporary file
|
| 38 |
|
| 39 |
+
# DEBUG: Confirming type and value of file_path
|
| 40 |
+
print(f"DEBUG: Type of file_path: {type(file_path)}")
|
| 41 |
+
print(f"DEBUG: Value of file_path: {file_path}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
# Pass the file_path string directly as the image input.
|
| 44 |
+
# Temporarily removed all optional parameters to isolate the image input issue.
|
|
|
|
|
|
|
|
|
|
| 45 |
result_path = client.predict(
|
| 46 |
+
image=file_path, # Pass the file path directly as a string
|
| 47 |
api_name="/predict",
|
| 48 |
)
|
| 49 |
|
|
|
|
| 60 |
if file_path and os.path.exists(file_path):
|
| 61 |
os.remove(file_path)
|
| 62 |
|
| 63 |
+
|
| 64 |
|
| 65 |
|
| 66 |
# 3️⃣ Set up the Gradio interface for the public space
|