Rahul8827 commited on
Commit
8fe1db9
·
1 Parent(s): d3b2ef1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -28
app.py CHANGED
@@ -5,8 +5,6 @@ from datetime import datetime
5
  import boto3
6
  import gradio as gr
7
 
8
-
9
-
10
  s3 = boto3.resource('s3')
11
 
12
  def Create_Organization(org_name, org_handle):
@@ -34,36 +32,26 @@ def Create_Organization(org_name, org_handle):
34
 
35
  return "Organization Created: " + o
36
 
37
- inputs = [
38
- gr.inputs.Textbox(label="Organization Name"),
39
- gr.inputs.Textbox(label="Organization Handle"),
40
- ]
41
- outputs = gr.outputs.Textbox(label="Message")
42
-
43
- gr.Interface(Create_Organization, inputs, outputs).launch()
44
-
45
-
46
- import gradio as gr
47
-
48
- def list_s3_folders(bucket_name):
49
- import boto3
50
 
51
- s3 = boto3.client('s3')
52
- result = s3.list_objects(Bucket=bucket_name, Delimiter='/')
53
 
54
  folders = [o.get('Prefix') for o in result.get('CommonPrefixes')]
55
- return folders
56
 
57
- iface2 = gr.Interface(
58
- fn=list_s3_folders,
59
- inputs="text",
60
- outputs="text",
61
- layout="vertical",
62
- title="List S3 Folders",
63
- description="Enter the S3 bucket name to list all folders in the bucket.",
64
- examples=[["myorg"]]
65
- )
66
 
67
- iface2.launch()
 
68
 
 
 
69
 
 
 
 
5
  import boto3
6
  import gradio as gr
7
 
 
 
8
  s3 = boto3.resource('s3')
9
 
10
  def Create_Organization(org_name, org_handle):
 
32
 
33
  return "Organization Created: " + o
34
 
35
+ def list_s3_folders():
36
+ s3_client = boto3.client('s3')
37
+ bucket_name = 'myorg'
 
 
 
 
 
 
 
 
 
 
38
 
39
+ result = s3_client.list_objects(Bucket=bucket_name, Delimiter='/')
 
40
 
41
  folders = [o.get('Prefix') for o in result.get('CommonPrefixes')]
42
+ return "\n".join(folders)
43
 
44
+ inputs_create_org = [
45
+ gr.inputs.Textbox(label="Organization Name"),
46
+ gr.inputs.Textbox(label="Organization Handle"),
47
+ ]
48
+ outputs_create_org = gr.outputs.Textbox(label="Message")
 
 
 
 
49
 
50
+ inputs_list_folders = None
51
+ outputs_list_folders = gr.outputs.Textbox(label="S3 Folders")
52
 
53
+ iface_create_org = gr.Interface(Create_Organization, inputs_create_org, outputs_create_org)
54
+ iface_list_folders = gr.Interface(list_s3_folders, inputs_list_folders, outputs_list_folders)
55
 
56
+ iface_create_org.launch()
57
+ iface_list_folders.launch()