File size: 1,904 Bytes
f429b1b
 
 
 
 
62d2cde
3a629c5
9431016
ecfd445
9431016
 
 
 
 
 
 
 
 
 
 
 
 
 
ecfd445
9431016
 
 
ecfd445
9431016
 
 
 
 
ecfd445
030ce18
8fe1db9
 
9431016
8fe1db9
9431016
 
8fe1db9
030ce18
 
 
 
f4ca8ae
030ce18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()