File size: 854 Bytes
2d11e5d
 
 
 
 
 
827a4e0
 
 
 
 
 
 
 
 
 
 
 
 
 
2d11e5d
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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()