Spaces:
Build error
Build error
Update app.py
Browse files25 unmodified lines262728293031323334353637383940414251 unmodified lines94959697989910010110210310410525 unmodified lines# Function to perform OCRdef ocr(input_file, lang='fas'): # 'fas': Persian language (Farsi)extracted_text = ""# Check if the input file is a PDF or an imageif isinstance(input_file, str) and input_file.endswith('.pdf'): # Check if the file is a PDF# Convert PDF to imagesimages = convert_from_path(input_file)# Loop through each image and perform OCRfor page_number, image in enumerate(images):text = pytesseract.image_to_string(image, lang=lang)extracted_text += textelif isinstance(input_file, Image.Image): # If the input is an imagetext = pytesseract.image_to_string(input_file, lang=lang)extracted_text = text51 unmodified lines"""def process(input_type, file, lang):if input_type == "PDF":extracted_text = ocr(file.name, lang)else:# image = Image.open(file.name)image = fileextracted_text = ocr(image, lang)return extracted_text25 unmodified lines26272829303151 unmodified lines8384858687888990919225 unmodified lines# Function to perform OCRdef ocr(input_file, lang='fas'): # 'fas': Persian language (Farsi)extracted_text = ""elif isinstance(input_file, Image.Image): # If the input is an imagetext = pytesseract.image_to_string(input_file, lang=lang)extracted_text = text51 unmodified lines"""def process(input_type, file, lang):# image = Image.open(file.name)image = fileextracted_text = ocr(image, lang)return extracted_text
app.py+4-17