Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ from fastapi.responses import Response
|
|
| 3 |
from PIL import Image
|
| 4 |
import io
|
| 5 |
import numpy as np
|
|
|
|
| 6 |
from super_image import EdsrModel, ImageLoader
|
| 7 |
|
| 8 |
app = FastAPI()
|
|
@@ -34,7 +35,12 @@ async def upscale(
|
|
| 34 |
img = Image.open(io.BytesIO(await image.read())).convert("RGB")
|
| 35 |
inputs = ImageLoader.load_image(img)
|
| 36 |
pred = model(inputs)
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
buffer = io.BytesIO()
|
| 40 |
result.save(buffer, format="PNG")
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import io
|
| 5 |
import numpy as np
|
| 6 |
+
import torch
|
| 7 |
from super_image import EdsrModel, ImageLoader
|
| 8 |
|
| 9 |
app = FastAPI()
|
|
|
|
| 35 |
img = Image.open(io.BytesIO(await image.read())).convert("RGB")
|
| 36 |
inputs = ImageLoader.load_image(img)
|
| 37 |
pred = model(inputs)
|
| 38 |
+
|
| 39 |
+
# pred is a tensor (1, 3, H, W) — convert to PIL manually
|
| 40 |
+
sr = pred.squeeze(0).clamp(0, 1).cpu().numpy()
|
| 41 |
+
sr = np.transpose(sr, (1, 2, 0))
|
| 42 |
+
sr = (sr * 255).astype(np.uint8)
|
| 43 |
+
result = Image.fromarray(sr)
|
| 44 |
|
| 45 |
buffer = io.BytesIO()
|
| 46 |
result.save(buffer, format="PNG")
|