Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import boto3 | |
| def upload_to_s3(bucket_name, file_name, file_data): | |
| s3 = boto3.resource('s3') | |
| bucket = s3.Bucket(bucket_name) | |
| bucket.put_object(Key=file_name, Body=file_data) | |
| def file_upload(workspace_name, document_name, document_file): | |
| # Assume the user is authenticated and has access to workspace_name | |
| # Store the document_file in the cloud storage solution for workspace_name | |
| bucket_name = f"{workspace_name}-bucket" | |
| upload_to_s3(bucket_name, document_name, document_file.read()) | |
| return f"Document {document_name} uploaded successfully to workspace {workspace_name}." | |
| workspace_input = gr.inputs.Textbox(label="Workspace Name") | |
| document_name_input = gr.inputs.Textbox(label="Document Name") | |
| document_file_input = gr.inputs.File(label="Document File") | |
| def upload(): | |
| # Check that user is authenticated and has access to workspace_input | |
| workspace_name = workspace_input.value | |
| document_name = document_name_input.value | |
| document_file = document_file_input.value | |
| return file_upload(workspace_name, document_name, document_file) | |
| app = gr.Interface(upload, inputs=[workspace_input, document_name_input, document_file_input], outputs="text") | |
| app.launch() | |