Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,28 @@
|
|
|
|
|
|
1 |
import torch
|
2 |
import gradio as gr
|
3 |
-
from inference_codeformer import inference
|
4 |
from fastapi import FastAPI, UploadFile, File
|
5 |
import uvicorn
|
6 |
from PIL import Image
|
7 |
import io
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
app = FastAPI()
|
10 |
|
11 |
-
# xyz
|
12 |
-
# vishal singh
|
13 |
# Load the CodeFormer model
|
14 |
model_path = "weights/CodeFormer.pth"
|
15 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
16 |
|
17 |
@app.post("/enhance")
|
18 |
async def enhance_image(file: UploadFile = File(...), upscale: int = 2, fidelity: float = 0.5):
|
|
|
19 |
image = Image.open(io.BytesIO(await file.read()))
|
20 |
image.save("input.png")
|
21 |
|
@@ -31,4 +38,3 @@ async def enhance_image(file: UploadFile = File(...), upscale: int = 2, fidelity
|
|
31 |
|
32 |
if __name__ == "__main__":
|
33 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
34 |
-
|
|
|
1 |
+
import sys
|
2 |
+
import os
|
3 |
import torch
|
4 |
import gradio as gr
|
|
|
5 |
from fastapi import FastAPI, UploadFile, File
|
6 |
import uvicorn
|
7 |
from PIL import Image
|
8 |
import io
|
9 |
|
10 |
+
# Ensure the `basicsr` directory is in the system path
|
11 |
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
12 |
+
sys.path.append(os.path.join(current_dir, "basicsr"))
|
13 |
+
|
14 |
+
# Import the inference function
|
15 |
+
from inference_codeformer import inference
|
16 |
+
|
17 |
app = FastAPI()
|
18 |
|
|
|
|
|
19 |
# Load the CodeFormer model
|
20 |
model_path = "weights/CodeFormer.pth"
|
21 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
22 |
|
23 |
@app.post("/enhance")
|
24 |
async def enhance_image(file: UploadFile = File(...), upscale: int = 2, fidelity: float = 0.5):
|
25 |
+
"""API Endpoint to enhance images using CodeFormer"""
|
26 |
image = Image.open(io.BytesIO(await file.read()))
|
27 |
image.save("input.png")
|
28 |
|
|
|
38 |
|
39 |
if __name__ == "__main__":
|
40 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|