NafishZaldinanda commited on
Commit
ed814a7
1 Parent(s): dda7386

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PyPDF2 import PdfReader
3
+ from PIL import Image
4
+
5
+ def process_file(file, file_type):
6
+ if file_type == "PDF":
7
+ # Membaca konten PDF
8
+ reader = PdfReader(file.name)
9
+ text = ""
10
+ for page in reader.pages:
11
+ text += page.extract_text()
12
+ return None, f"File PDF berisi:\n{text}"
13
+ elif file_type == "Image":
14
+ # Menampilkan gambar
15
+ image = Image.open(file.name)
16
+ return image, None
17
+
18
+ # Buat antarmuka Gradio
19
+ file_type_radio = gr.Radio(choices=["Image", "PDF"], label="Pilih tipe file")
20
+ file_input = gr.File(label="Unggah file", file_types=["image", "pdf"])
21
+
22
+ interface = gr.Interface(
23
+ fn=process_file,
24
+ inputs=[file_input, file_type_radio],
25
+ outputs=[gr.Image(type="pil", label="Hasil Gambar"), gr.Textbox(label="Hasil PDF")],
26
+ title="Proses File Gambar dan PDF",
27
+ description="Pilih tipe file dan unggah file gambar atau PDF untuk diproses."
28
+ )
29
+
30
+ # Jalankan antarmuka tanpa opsi share=True
31
+ interface.launch()