raghav commited on
Commit ·
732911b
1
Parent(s): 3e29b7e
Fix: Use handle_file() for proper gradio_client file upload
Browse files
app.py
CHANGED
|
@@ -29,21 +29,27 @@ def classify_material(image):
|
|
| 29 |
|
| 30 |
try:
|
| 31 |
import tempfile
|
| 32 |
-
from PIL import Image
|
|
|
|
| 33 |
|
| 34 |
print(f"📤 Calling backend API with image type: {type(image)}")
|
| 35 |
|
| 36 |
# Convert PIL Image to temp file for gradio_client
|
| 37 |
-
if isinstance(image,
|
| 38 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix='.jpg') as tmp:
|
| 39 |
-
image.save(tmp
|
| 40 |
image_path = tmp.name
|
| 41 |
else:
|
| 42 |
image_path = image
|
| 43 |
|
| 44 |
-
|
|
|
|
|
|
|
| 45 |
client = get_backend()
|
| 46 |
-
result = client.predict(
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
print(f"📥 Backend response: {result}")
|
| 49 |
|
|
|
|
| 29 |
|
| 30 |
try:
|
| 31 |
import tempfile
|
| 32 |
+
from PIL import Image as PILImage
|
| 33 |
+
from gradio_client import handle_file
|
| 34 |
|
| 35 |
print(f"📤 Calling backend API with image type: {type(image)}")
|
| 36 |
|
| 37 |
# Convert PIL Image to temp file for gradio_client
|
| 38 |
+
if isinstance(image, PILImage.Image):
|
| 39 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.jpg', mode='wb') as tmp:
|
| 40 |
+
image.save(tmp, 'JPEG')
|
| 41 |
image_path = tmp.name
|
| 42 |
else:
|
| 43 |
image_path = image
|
| 44 |
|
| 45 |
+
print(f"📤 Sending file: {image_path}")
|
| 46 |
+
|
| 47 |
+
# Call protected space API with properly formatted file
|
| 48 |
client = get_backend()
|
| 49 |
+
result = client.predict(
|
| 50 |
+
image=handle_file(image_path),
|
| 51 |
+
api_name="/classify_material"
|
| 52 |
+
)
|
| 53 |
|
| 54 |
print(f"📥 Backend response: {result}")
|
| 55 |
|