Spaces:
Sleeping
Sleeping
Initial commit
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
API_URL = "https://dssa9yu3o7.execute-api.ap-south-1.amazonaws.com/dev/generatePresignedUrlApi"
|
| 6 |
+
|
| 7 |
+
def upload_pdf(file):
|
| 8 |
+
filename = file.name
|
| 9 |
+
content_type = "application/pdf"
|
| 10 |
+
|
| 11 |
+
# Step 1: Get pre-signed URL
|
| 12 |
+
response = requests.post(API_URL, json={"filename": filename, "contentType": content_type})
|
| 13 |
+
if response.status_code != 200:
|
| 14 |
+
return "Failed to get upload URL"
|
| 15 |
+
|
| 16 |
+
upload_url = response.json().get("uploadURL")
|
| 17 |
+
|
| 18 |
+
# Step 2: Upload to S3
|
| 19 |
+
with open(file.name, "rb") as f:
|
| 20 |
+
upload_response = requests.put(upload_url, data=f, headers={"Content-Type": content_type})
|
| 21 |
+
|
| 22 |
+
if upload_response.status_code == 200:
|
| 23 |
+
return "✅ Upload successful!"
|
| 24 |
+
else:
|
| 25 |
+
return f"❌ Upload failed: {upload_response.status_code}"
|
| 26 |
+
|
| 27 |
+
ui = gr.Interface(
|
| 28 |
+
fn=upload_pdf,
|
| 29 |
+
inputs=gr.File(file_types=[".pdf"]),
|
| 30 |
+
outputs="text",
|
| 31 |
+
title="Upload PDF to S3",
|
| 32 |
+
description="Select a PDF file to upload to AWS S3 via pre-signed URL"
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
ui.launch()
|