| import gradio as gr |
| from PIL import Image |
| import base64 |
| import io |
|
|
| def convert_base64_to_jpg(image_base64): |
| |
| if image_base64.startswith("data:image"): |
| image_base64 = image_base64.split(",")[1] |
|
|
| try: |
| |
| img_data = base64.b64decode(image_base64) |
| |
| image = Image.open(io.BytesIO(img_data)) |
| |
| image.save('converted_image.jpg', 'JPEG') |
| return 'converted_image.jpg' |
| except Exception as e: |
| return f"Erro ao processar a imagem: {str(e)}" |
|
|
| |
| iface = gr.Interface(fn=convert_base64_to_jpg, |
| inputs=gr.Textbox(placeholder="Insira base64 aqui", lines=5), |
| outputs="file") |
|
|
| iface.launch() |
|
|