Spaces:
Runtime error
Runtime error
File size: 1,641 Bytes
470ac18 2437668 470ac18 2437668 470ac18 2437668 470ac18 2437668 470ac18 2437668 470ac18 2437668 6921844 470ac18 2437668 470ac18 2437668 470ac18 2437668 470ac18 2437668 470ac18 6921844 470ac18 6921844 470ac18 082a70a 470ac18 | 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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | import gradio as gr
from PIL import Image
import os
import subprocess
import glob
def get_latest_file(directory):
all_items = glob.glob(os.path.join(directory, '*'))
folders = [item for item in all_items if os.path.isdir(item)]
files = [item for item in all_items if os.path.isfile(item)]
if folders:
latest_folder = max(folders, key=os.path.getmtime)
return latest_folder
elif files:
latest_file = max(files, key=os.path.getmtime)
return latest_file
else:
return None
def save_image(image):
directory = './testdata'
if not os.path.exists(directory):
os.makedirs(directory)
image.save(os.path.join(directory, 'new_image_1.jpg'))
def process_image(image):
pil_image = Image.fromarray(image)
save_image(pil_image)
program_path = './test.py'
subprocess.run(['python3', program_path, '--data_path_test=./testdata'])
directory_image = './flat'
latest_file = get_latest_file(get_latest_file(directory_image))
image_path = f'{latest_file}/144/test/new_image_1.jpg'
new_image = Image.open(image_path)
return new_image
iface = gr.Interface(fn=process_image,
inputs="image",
outputs="image",
title="Document dewarping platform",
description="This page recognises wrinkled documents and processes them into flat ones, you can upload your local images and download the processed files.",
allow_flagging="never"
)
iface.launch()
|