Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ import io
|
|
11 |
import base64
|
12 |
import logging
|
13 |
import runpod
|
|
|
14 |
|
15 |
# Add logging configuration right after
|
16 |
logging.basicConfig(level=logging.INFO)
|
@@ -301,32 +302,48 @@ def base64_to_pil(base64_str):
|
|
301 |
# Simple RunPod handler that forwards to stream_chat
|
302 |
def handler(event):
|
303 |
try:
|
304 |
-
|
305 |
-
|
306 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
# Convert base64 image to PIL Image
|
308 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
309 |
|
310 |
-
#
|
311 |
-
|
312 |
-
input_image=
|
313 |
-
caption_type=
|
314 |
-
caption_length=
|
315 |
-
extra_options=
|
316 |
-
name_input=
|
317 |
-
custom_prompt=
|
318 |
)
|
319 |
|
320 |
return {
|
321 |
-
"output":
|
322 |
-
"prompt": prompt,
|
323 |
-
"caption": caption
|
324 |
-
}
|
325 |
}
|
326 |
-
|
327 |
except Exception as e:
|
328 |
-
|
329 |
-
|
|
|
|
|
330 |
|
331 |
if __name__ == "__main__":
|
332 |
# Start RunPod serverless
|
|
|
11 |
import base64
|
12 |
import logging
|
13 |
import runpod
|
14 |
+
import requests
|
15 |
|
16 |
# Add logging configuration right after
|
17 |
logging.basicConfig(level=logging.INFO)
|
|
|
302 |
# Simple RunPod handler that forwards to stream_chat
|
303 |
def handler(event):
|
304 |
try:
|
305 |
+
# Extract data from the Runpod event
|
306 |
+
data = event["input"]
|
307 |
|
308 |
+
# Check if input is a dictionary (which seems to be the case from the error)
|
309 |
+
if isinstance(data["input_image"], dict):
|
310 |
+
return {
|
311 |
+
"status": "error",
|
312 |
+
"message": "Invalid image format. Expected base64 string or file data."
|
313 |
+
}
|
314 |
+
|
315 |
# Convert base64 image to PIL Image
|
316 |
+
if isinstance(data["input_image"], str):
|
317 |
+
# Remove data URL prefix if present
|
318 |
+
if 'base64,' in data["input_image"]:
|
319 |
+
data["input_image"] = data["input_image"].split('base64,')[1]
|
320 |
+
image_data = base64.b64decode(data["input_image"])
|
321 |
+
image = Image.open(io.BytesIO(image_data))
|
322 |
+
else:
|
323 |
+
return {
|
324 |
+
"status": "error",
|
325 |
+
"message": "Invalid image format"
|
326 |
+
}
|
327 |
|
328 |
+
# Now we have a valid PIL Image, proceed with the stream_chat call
|
329 |
+
result = stream_chat(
|
330 |
+
input_image=image,
|
331 |
+
caption_type=data.get("caption_type", "Descriptive"),
|
332 |
+
caption_length=data.get("caption_length", "any"),
|
333 |
+
extra_options=data.get("extra_options", []),
|
334 |
+
name_input=data.get("name_input", ""),
|
335 |
+
custom_prompt=data.get("custom_prompt", "")
|
336 |
)
|
337 |
|
338 |
return {
|
339 |
+
"output": result
|
|
|
|
|
|
|
340 |
}
|
341 |
+
|
342 |
except Exception as e:
|
343 |
+
return {
|
344 |
+
"status": "error",
|
345 |
+
"message": str(e)
|
346 |
+
}
|
347 |
|
348 |
if __name__ == "__main__":
|
349 |
# Start RunPod serverless
|