05prey commited on
Commit
084a82a
·
verified ·
1 Parent(s): e83da5a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, time
2
+ from fastapi import FastAPI, UploadFile, File
3
+ from fastapi.responses import HTMLResponse
4
+
5
+ app = FastAPI()
6
+
7
+ @app.get("/", response_class=HTMLResponse)
8
+ def home():
9
+ return """
10
+ <h2>Dummy Upload Sink</h2>
11
+ <p>POST a file to <code>/upload</code> to measure upload speed.</p>
12
+ <pre>
13
+ curl -X POST https://YOUR_SPACE_URL/upload -F "file=@study.zip"
14
+ </pre>
15
+ """
16
+
17
+ @app.post("/upload")
18
+ async def upload_sink(file: UploadFile = File(...)):
19
+ start = time.time()
20
+ total = 0
21
+ while True:
22
+ chunk = await file.read(1024 * 1024) # 1MB chunks
23
+ if not chunk:
24
+ break
25
+ total += len(chunk)
26
+
27
+ dt = time.time() - start
28
+ mb = total / (1024**2)
29
+ return {
30
+ "filename": file.filename,
31
+ "received_mb": round(mb, 2),
32
+ "duration_sec": round(dt, 2),
33
+ "throughput_mb_s": round(mb / dt, 2) if dt > 0 else 0.0,
34
+ }