Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Importação de biblioteca
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
def converter_imagem(imagem):
|
| 7 |
+
|
| 8 |
+
try:
|
| 9 |
+
if imagem.mode != 'RGB':
|
| 10 |
+
imagem = imagem.convert('RGB')
|
| 11 |
+
caminho_pdf = "resultado.pdf"
|
| 12 |
+
imagem.save(caminho_pdf, "PDF", resolution=100.0)
|
| 13 |
+
|
| 14 |
+
return caminho_pdf
|
| 15 |
+
|
| 16 |
+
except Exception as e:
|
| 17 |
+
return (f"Um erro ocorreu: {e}")
|
| 18 |
+
|
| 19 |
+
# Configuração da interface
|
| 20 |
+
interface = gr.Interface(
|
| 21 |
+
fn=converter_imagem,
|
| 22 |
+
inputs=gr.Image(type="pil"), # Recebe o arquivo e trata como objeto PIL
|
| 23 |
+
outputs=gr.File(label="Baixe seu PDF aqui"),
|
| 24 |
+
title="Conversor de JPG para PDF",
|
| 25 |
+
description="Suba sua imagem e aguarde o processamento."
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
# Iniciar o app
|
| 29 |
+
interface.launch(share=True)
|