NafishZaldinanda commited on
Commit
7fbfc5b
1 Parent(s): 3d57420

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -1,15 +1,15 @@
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)
@@ -27,5 +27,5 @@ interface = gr.Interface(
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()
 
1
  import gradio as gr
2
  from PyPDF2 import PdfReader
3
+ from pdf2image import convert_from_path
4
  from PIL import Image
5
 
6
  def process_file(file, file_type):
7
  if file_type == "PDF":
8
+ # Mengonversi PDF ke gambar
9
+ images = convert_from_path(file.name)
10
+ # Menyimpan gambar pertama sebagai output
11
+ image = images[0] # Mengambil halaman pertama
12
+ return image, None
 
13
  elif file_type == "Image":
14
  # Menampilkan gambar
15
  image = Image.open(file.name)
 
27
  description="Pilih tipe file dan unggah file gambar atau PDF untuk diproses."
28
  )
29
 
30
+ # Jalankan antarmuka dengan opsi share=True
31
  interface.launch()