Team Ai
Apppublic

mushroomsolutions/workflow_document_processing

sourceHugging Facemitupdated 4y agoView on Hugging Face
0likes
app.py56 linesDownload Raw Back to root
1import os2import gradio as gr3from werkzeug.utils import secure_filename4 5UPLOAD_FOLDER = './'6ALLOWED_EXTENSIONS = {'txt', 'pdf', 'doc', 'docx', 'png', 'jpg', 'jpeg', 'gif'}7 8app = gr.Interface(9    fn=None,10    inputs=None,11    outputs=None,12    title='Workspace Uploader',13    description='Upload documents into a workspace',14    theme='default',15    layout='wide',16    allow_flagging=False,17    analytics_enabled=False,18    server_name=None,19)20 21def allowed_file(filename):22    return '.' in filename and \23           filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS24 25def upload_file(request):26    if request.method == 'POST':27        # check if the post request has the file part28        if 'file' not in request.files:29            return 'No file part'30        file = request.files['file']31        # if user does not select file, browser also32        # submit an empty part without filename33        if file.filename == '':34            return 'No selected file'35        if file and allowed_file(file.filename):36            filename = secure_filename(file.filename)37            file.save(os.path.join(UPLOAD_FOLDER, filename))38            return 'File uploaded successfully'39        else:40            return 'File not allowed'41 42@app.interface(43    "textbox",44    "file",45    live=True46)47def upload_to_workspace(text, file):48    if file is not None:49        upload_file(file)50        return 'File uploaded successfully'51    else:52        return 'No file selected'53 54if __name__ == '__main__':55    app.launch()56