import json import socket import os from datetime import datetime import boto3 import gradio as gr s3 = boto3.resource('s3') def Create_Organization(org_name, org_handle): on = org_name o = org_handle path = o isExist = os.path.exists(path) hostname = socket.gethostname() now = datetime.now() tim = now.strftime("%d/%m/%Y %H:%M:%S") Organizationdetails = {} Organizationdetails[org_handle] = {} Organizationdetails[org_handle]['Organizationame'] = org_name Organizationdetails[org_handle]['OrganizationHandle'] = org_handle Organizationdetails[org_handle]['Created_by'] = hostname Organizationdetails[org_handle]['Created_Time'] = tim # Create a bucket in S3 bucket_name = 'myorg' bucket = s3.Bucket(bucket_name) # Save the organization details to S3 bucket key = org_name + '/Organizationdetails.json' blob = bucket.put_object(Key=key, Body=json.dumps(Organizationdetails)) return "Organization Created: " + o def list_of_organization(): s3_client = boto3.client('s3') bucket_name = 'myorg' result = s3_client.list_objects(Bucket=bucket_name, Delimiter='/') folders = [o.get('Prefix') for o in result.get('CommonPrefixes')] return "\n".join(folders) def main_function(action, org_name=None, org_handle=None): if action == "Create Organization": return Create_Organization(org_name, org_handle) elif action == "list_of_organization": return list_of_organization() interface = gr.Interface( fn=main_function, inputs=[ gr.inputs.Dropdown( choices=["Create Organization", "list_of_organization"], label="Select an Action" ), gr.inputs.Textbox(label="Organization Name"), gr.inputs.Textbox(label="Organization Handle"), ], outputs=gr.outputs.Textbox(label="Message"), ) interface.launch()