raghav commited on
Commit
3e29b7e
·
1 Parent(s): 8773f23

Fix: Save PIL Image to temp file before API call

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -28,11 +28,22 @@ def classify_material(image):
28
  return "Please upload an image", "", ""
29
 
30
  try:
 
 
 
31
  print(f"📤 Calling backend API with image type: {type(image)}")
32
 
 
 
 
 
 
 
 
 
33
  # Call protected space API
34
  client = get_backend()
35
- result = client.predict(image=image, api_name="/classify_material")
36
 
37
  print(f"📥 Backend response: {result}")
38
 
 
28
  return "Please upload an 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, Image.Image):
38
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.jpg') as tmp:
39
+ image.save(tmp.name, 'JPEG')
40
+ image_path = tmp.name
41
+ else:
42
+ image_path = image
43
+
44
  # Call protected space API
45
  client = get_backend()
46
+ result = client.predict(image=image_path, api_name="/classify_material")
47
 
48
  print(f"📥 Backend response: {result}")
49