File size: 1,054 Bytes
ed814a7
 
7fbfc5b
ed814a7
 
 
 
7fbfc5b
 
 
 
 
ed814a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7fbfc5b
ed814a7
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
29
30
31
32
import gradio as gr
from PyPDF2 import PdfReader
from pdf2image import convert_from_path
from PIL import Image

def process_file(file, file_type):
    if file_type == "PDF":
        # Mengonversi PDF ke gambar
        images = convert_from_path(file.name)
        # Menyimpan gambar pertama sebagai output
        image = images[0]  # Mengambil halaman pertama
        return image, None
    elif file_type == "Image":
        # Menampilkan gambar
        image = Image.open(file.name)
        return image, None

# Buat antarmuka Gradio
file_type_radio = gr.Radio(choices=["Image", "PDF"], label="Pilih tipe file")
file_input = gr.File(label="Unggah file", file_types=["image", "pdf"])

interface = gr.Interface(
    fn=process_file,
    inputs=[file_input, file_type_radio],
    outputs=[gr.Image(type="pil", label="Hasil Gambar"), gr.Textbox(label="Hasil PDF")],
    title="Proses File Gambar dan PDF",
    description="Pilih tipe file dan unggah file gambar atau PDF untuk diproses."
)

# Jalankan antarmuka dengan opsi share=True
interface.launch()