Spaces:
Runtime error
Runtime error
Commit
·
5fb1a7a
1
Parent(s):
bd0265d
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import boto3
|
| 3 |
+
|
| 4 |
+
def upload_to_s3(bucket_name, file_name, file_data):
|
| 5 |
+
s3 = boto3.resource('s3')
|
| 6 |
+
bucket = s3.Bucket(bucket_name)
|
| 7 |
+
bucket.put_object(Key=file_name, Body=file_data)
|
| 8 |
+
|
| 9 |
+
def file_upload(workspace_name, document_name, document_file):
|
| 10 |
+
# Assume the user is authenticated and has access to workspace_name
|
| 11 |
+
# Store the document_file in the cloud storage solution for workspace_name
|
| 12 |
+
bucket_name = f"{workspace_name}-bucket"
|
| 13 |
+
upload_to_s3(bucket_name, document_name, document_file.read())
|
| 14 |
+
return f"Document {document_name} uploaded successfully to workspace {workspace_name}."
|
| 15 |
+
|
| 16 |
+
workspace_input = gr.inputs.Textbox(label="Workspace Name")
|
| 17 |
+
document_name_input = gr.inputs.Textbox(label="Document Name")
|
| 18 |
+
document_file_input = gr.inputs.File(label="Document File")
|
| 19 |
+
|
| 20 |
+
def upload():
|
| 21 |
+
# Check that user is authenticated and has access to workspace_input
|
| 22 |
+
workspace_name = workspace_input.value
|
| 23 |
+
document_name = document_name_input.value
|
| 24 |
+
document_file = document_file_input.value
|
| 25 |
+
return file_upload(workspace_name, document_name, document_file)
|
| 26 |
+
|
| 27 |
+
app = gr.Interface(upload, inputs=[workspace_input, document_name_input, document_file_input], outputs="text")
|
| 28 |
+
app.launch()
|