Download app.py from 13ze/base64: direct link, hf CLI and curl.
- Browser
- Download file 854 Bytes
-
https://huggingface.co/spaces/13ze/base64/resolve/main/app.py
- Command line
-
hf download hf://spaces/13ze/base64/app.py
-
curl -L -o app.py https://huggingface.co/spaces/13ze/base64/resolve/main/app.py
854 Bytes
| import gradio as gr | |
| from PIL import Image | |
| import base64 | |
| import io | |
| def convert_base64_to_jpg(image_base64): | |
| # Se o base64 contiver o prefixo 'data:image/png;base64,', remova-o | |
| if image_base64.startswith("data:image"): | |
| image_base64 = image_base64.split(",")[1] | |
| try: | |
| # Decodifica o base64 | |
| img_data = base64.b64decode(image_base64) | |
| # Cria a imagem | |
| image = Image.open(io.BytesIO(img_data)) | |
| # Salva a imagem como JPG | |
| image.save('converted_image.jpg', 'JPEG') | |
| return 'converted_image.jpg' | |
| except Exception as e: | |
| return f"Erro ao processar a imagem: {str(e)}" | |
| # Cria a interface Gradio | |
| iface = gr.Interface(fn=convert_base64_to_jpg, | |
| inputs=gr.Textbox(placeholder="Insira base64 aqui", lines=5), | |
| outputs="file") | |
| iface.launch() | |