Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,44 +5,47 @@ from datetime import datetime
|
|
| 5 |
import boto3
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
s3 = boto3.
|
| 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 |
-
org_names = ", ".join(organizations)
|
| 42 |
inputs = [
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
]
|
| 46 |
-
outputs = [gr.outputs.Textbox(gr.outputs.Textbox(label="Existing Organizations"),gr.outputs.Textbox(label="Message")]
|
| 47 |
|
| 48 |
-
gr.Interface(
|
|
|
|
| 5 |
import boto3
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
+
# S3 client
|
| 9 |
+
s3 = boto3.client('s3')
|
| 10 |
+
|
| 11 |
+
# Bucket name
|
| 12 |
+
bucket_name = 'your_bucket_name'
|
| 13 |
+
|
| 14 |
+
def create_organization(org_name, org_handle):
|
| 15 |
+
|
| 16 |
+
# Create organization
|
| 17 |
+
org_details = {
|
| 18 |
+
'name': org_name,
|
| 19 |
+
'handle': org_handle,
|
| 20 |
+
'created_by': socket.gethostname(),
|
| 21 |
+
'created_at': datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
# Save to S3
|
| 25 |
+
s3.put_object(
|
| 26 |
+
Bucket=bucket_name,
|
| 27 |
+
Key=f"{org_handle}/details.json",
|
| 28 |
+
Body=json.dumps(org_details)
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
# Get existing organizations
|
| 32 |
+
existing_orgs = []
|
| 33 |
+
objects = s3.list_objects(Bucket=bucket_name)['Contents']
|
| 34 |
+
|
| 35 |
+
for obj in objects:
|
| 36 |
+
data = json.loads(s3.get_object(Bucket=bucket_name, Key=obj['Key'])['Body'].read())
|
| 37 |
+
existing_orgs.append(data['name'])
|
| 38 |
+
|
| 39 |
+
return ", ".join(existing_orgs)
|
| 40 |
+
|
|
|
|
| 41 |
inputs = [
|
| 42 |
+
gr.inputs.Textbox(label="Organization Name"),
|
| 43 |
+
gr.inputs.Textbox(label="Organization Handle")
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
outputs = [
|
| 47 |
+
gr.outputs.Textbox(label="Existing Organizations"),
|
| 48 |
+
gr.outputs.Textbox(label="Message")
|
| 49 |
]
|
|
|
|
| 50 |
|
| 51 |
+
gr.Interface(fn=create_organization, inputs=inputs, outputs=outputs).launch()
|