Spaces:
Sleeping
Sleeping
Rahul-Samedavar commited on
Commit ·
dba317c
1
Parent(s): 95c13e7
sec
Browse files- Dockerfile +0 -1
- app.py +11 -12
Dockerfile
CHANGED
|
@@ -29,6 +29,5 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 29 |
|
| 30 |
COPY . .
|
| 31 |
|
| 32 |
-
RUN where realesrgan-ncnn-vulkan
|
| 33 |
|
| 34 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 29 |
|
| 30 |
COPY . .
|
| 31 |
|
|
|
|
| 32 |
|
| 33 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
CHANGED
|
@@ -25,25 +25,24 @@ def home():
|
|
| 25 |
@app.post("/enhance")
|
| 26 |
async def enhance_image(file: UploadFile = File(...)):
|
| 27 |
input_name = f"{uuid.uuid4()}_{file.filename}"
|
| 28 |
-
output_name = f"enhanced_{input_name}"
|
| 29 |
-
|
| 30 |
input_path = os.path.join(OUTPUT_DIR, input_name)
|
| 31 |
-
output_path = os.path.join(OUTPUT_DIR, output_name)
|
| 32 |
|
| 33 |
with open(input_path, "wb") as buffer:
|
| 34 |
shutil.copyfileobj(file.file, buffer)
|
| 35 |
|
| 36 |
cmd = [
|
| 37 |
-
|
| 38 |
"-i", input_path,
|
| 39 |
-
"-o",
|
| 40 |
-
"-s", "2"
|
|
|
|
| 41 |
]
|
| 42 |
|
| 43 |
-
subprocess.run(cmd,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
return FileResponse(
|
| 46 |
-
output_path,
|
| 47 |
-
media_type="image/png",
|
| 48 |
-
filename=output_name
|
| 49 |
-
)
|
|
|
|
| 25 |
@app.post("/enhance")
|
| 26 |
async def enhance_image(file: UploadFile = File(...)):
|
| 27 |
input_name = f"{uuid.uuid4()}_{file.filename}"
|
|
|
|
|
|
|
| 28 |
input_path = os.path.join(OUTPUT_DIR, input_name)
|
|
|
|
| 29 |
|
| 30 |
with open(input_path, "wb") as buffer:
|
| 31 |
shutil.copyfileobj(file.file, buffer)
|
| 32 |
|
| 33 |
cmd = [
|
| 34 |
+
"realesrgan-ncnn-vulkan",
|
| 35 |
"-i", input_path,
|
| 36 |
+
"-o", OUTPUT_DIR,
|
| 37 |
+
"-s", "2",
|
| 38 |
+
"-m", "/opt/realesrgan/models"
|
| 39 |
]
|
| 40 |
|
| 41 |
+
result = subprocess.run(cmd, capture_output=True, text=True)
|
| 42 |
+
|
| 43 |
+
if result.returncode != 0:
|
| 44 |
+
raise HTTPException(status_code=500, detail=result.stderr)
|
| 45 |
+
|
| 46 |
+
enhanced = os.path.join(OUTPUT_DIR, f"enhanced_{input_name}")
|
| 47 |
|
| 48 |
+
return FileResponse(enhanced, media_type="image/png")
|
|
|
|
|
|
|
|
|
|
|
|