Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
-
import
|
| 2 |
import gradio as gr
|
| 3 |
from fastapi import FastAPI, UploadFile, File
|
| 4 |
-
import uvicorn
|
| 5 |
|
| 6 |
api = FastAPI()
|
| 7 |
|
|
@@ -10,7 +9,7 @@ async def upload_sink(file: UploadFile = File(...)):
|
|
| 10 |
start = time.time()
|
| 11 |
total = 0
|
| 12 |
while True:
|
| 13 |
-
chunk = await file.read(1024 * 1024)
|
| 14 |
if not chunk:
|
| 15 |
break
|
| 16 |
total += len(chunk)
|
|
@@ -18,20 +17,16 @@ async def upload_sink(file: UploadFile = File(...)):
|
|
| 18 |
dt = time.time() - start
|
| 19 |
mb = total / (1024**2)
|
| 20 |
return {
|
| 21 |
-
"filename": file.filename,
|
| 22 |
"received_mb": round(mb, 2),
|
| 23 |
"duration_sec": round(dt, 2),
|
| 24 |
"throughput_mb_s": round(mb / dt, 2) if dt > 0 else 0.0,
|
|
|
|
|
|
|
| 25 |
}
|
| 26 |
|
| 27 |
-
# --- your existing Gradio Blocks (keep your UI code here)
|
| 28 |
with gr.Blocks() as demo:
|
| 29 |
-
gr.Markdown("## Dummy upload sink
|
|
|
|
| 30 |
|
| 31 |
-
#
|
| 32 |
app = gr.mount_gradio_app(api, demo, path="/")
|
| 33 |
-
|
| 34 |
-
# IMPORTANT: start the server so the process doesn't exit
|
| 35 |
-
if __name__ == "__main__":
|
| 36 |
-
port = int(os.environ.get("PORT", "7860"))
|
| 37 |
-
uvicorn.run(app, host="0.0.0.0", port=port)
|
|
|
|
| 1 |
+
import time
|
| 2 |
import gradio as gr
|
| 3 |
from fastapi import FastAPI, UploadFile, File
|
|
|
|
| 4 |
|
| 5 |
api = FastAPI()
|
| 6 |
|
|
|
|
| 9 |
start = time.time()
|
| 10 |
total = 0
|
| 11 |
while True:
|
| 12 |
+
chunk = await file.read(1024 * 1024)
|
| 13 |
if not chunk:
|
| 14 |
break
|
| 15 |
total += len(chunk)
|
|
|
|
| 17 |
dt = time.time() - start
|
| 18 |
mb = total / (1024**2)
|
| 19 |
return {
|
|
|
|
| 20 |
"received_mb": round(mb, 2),
|
| 21 |
"duration_sec": round(dt, 2),
|
| 22 |
"throughput_mb_s": round(mb / dt, 2) if dt > 0 else 0.0,
|
| 23 |
+
"filename": file.filename,
|
| 24 |
+
"content_type": file.content_type,
|
| 25 |
}
|
| 26 |
|
|
|
|
| 27 |
with gr.Blocks() as demo:
|
| 28 |
+
gr.Markdown("## Dummy upload sink")
|
| 29 |
+
gr.Markdown("POST to `/upload` to measure upload bandwidth.")
|
| 30 |
|
| 31 |
+
# Expose FastAPI+Gradio app (Spaces will run it)
|
| 32 |
app = gr.mount_gradio_app(api, demo, path="/")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|