|
--- |
|
title: Run My Script |
|
emoji: π |
|
colorFrom: red |
|
colorTo: indigo |
|
sdk: gradio |
|
sdk_version: 5.33.0 |
|
app_file: app.py |
|
pinned: false |
|
license: mit |
|
short_description: creates a venv, install dependencies and run your script |
|
--- |
|
|
|
## run_my_script |
|
|
|
test script: |
|
```python |
|
import os |
|
import base64 |
|
from io import BytesIO |
|
from PIL import Image |
|
import json |
|
|
|
input_path = os.environ["SCRIPT_INPUT"] |
|
output_path = os.environ["SCRIPT_OUTPUT"] |
|
|
|
# Load JSON input |
|
with open(input_path, "r") as f: |
|
data = json.load(f) |
|
img_b64 = data["img"] |
|
|
|
# Decode base64 to image |
|
img_bytes = base64.b64decode(img_b64) |
|
img = Image.open(BytesIO(img_bytes)) |
|
img.load() # β¬
οΈ Ensure image is fully loaded before processing |
|
|
|
# Flip image horizontally |
|
flipped = img.transpose(Image.FLIP_LEFT_RIGHT) |
|
|
|
# Save output |
|
flipped.save(os.path.join(output_path, "flipped.png")) |
|
print("Image flipped and saved as flipped.png.") |
|
``` |
|
|
|
input: |
|
```json |
|
{ |
|
"img": "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAIAAADTED8xAAADMElEQVR4nOzVwQnAIBQFQYXff81RUkQCOyDj1YOPnbXWPmeTRef+/3O/OyBjzh3CD95BfqICMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK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