Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -147,10 +147,19 @@ def process_image(image_input):
|
|
| 147 |
# Initialize the Gradio client with the URL of the Gradio server
|
| 148 |
client = Client("https://adept-fuyu-8b-demo.hf.space/--replicas/pqjvl/")
|
| 149 |
|
| 150 |
-
# Check if the image input is a file path (str) or a PIL Image
|
| 151 |
if isinstance(image_input, str):
|
| 152 |
-
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
else:
|
| 155 |
# Assuming it's a PIL Image, save it to a temporary file
|
| 156 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as tmp_file:
|
|
@@ -165,7 +174,7 @@ def process_image(image_input):
|
|
| 165 |
)
|
| 166 |
|
| 167 |
# Clean up the temporary file if created
|
| 168 |
-
if not isinstance(image_input, str):
|
| 169 |
os.remove(image_path)
|
| 170 |
|
| 171 |
return result
|
|
|
|
| 147 |
# Initialize the Gradio client with the URL of the Gradio server
|
| 148 |
client = Client("https://adept-fuyu-8b-demo.hf.space/--replicas/pqjvl/")
|
| 149 |
|
| 150 |
+
# Check if the image input is a base64 string, file path (str), or a PIL Image
|
| 151 |
if isinstance(image_input, str):
|
| 152 |
+
try:
|
| 153 |
+
# Try to decode if it's a base64 string
|
| 154 |
+
image = decode_image(image_input)
|
| 155 |
+
except Exception:
|
| 156 |
+
# If decoding fails, assume it's a file path or a URL
|
| 157 |
+
image_path = image_input
|
| 158 |
+
else:
|
| 159 |
+
# If decoding succeeds, save the decoded image to a temporary file
|
| 160 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as tmp_file:
|
| 161 |
+
image.save(tmp_file.name)
|
| 162 |
+
image_path = tmp_file.name
|
| 163 |
else:
|
| 164 |
# Assuming it's a PIL Image, save it to a temporary file
|
| 165 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as tmp_file:
|
|
|
|
| 174 |
)
|
| 175 |
|
| 176 |
# Clean up the temporary file if created
|
| 177 |
+
if not isinstance(image_input, str) or isinstance(image_input, str) and 'tmp' in image_path:
|
| 178 |
os.remove(image_path)
|
| 179 |
|
| 180 |
return result
|