Spaces:
Sleeping
Sleeping
File size: 2,472 Bytes
e40c95c 7aacbb3 4677b33 7aacbb3 1106a9f 4677b33 e40c95c eda498a 273d6eb eda498a e40c95c 7aacbb3 e40c95c 7aacbb3 4677b33 7aacbb3 eda498a 7aacbb3 f1d72e1 7aacbb3 f1d72e1 3923e8c 4a4d2f6 e40c95c 7aacbb3 78eae8c cf58652 78eae8c e40c95c 1106a9f eda498a 1106a9f e40c95c eda498a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
import os
import random
import gradio as gr
from PIL import Image
import torch
from random import randint
import sys
import psutil
import subprocess
def run_cmd(command):
try:
print(f"Running command: {command}")
# Run the command and capture both output and error
result = subprocess.run(command, shell=True, text=True, capture_output=True)
# Print stdout and stderr
if result.stdout:
print("Output:\n", result.stdout)
if result.stderr:
print("Error:\n", result.stderr)
# Check for command success
if result.returncode != 0:
print(f"Command failed with return code {result.returncode}")
except KeyboardInterrupt:
print("Process interrupted")
sys.exit(1)
run_cmd("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P .")
run_cmd("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P .")
def inference(img,mode):
_id = randint(1, 10000)
INPUT_DIR = "./tmp/input_image" + str(_id) + "/"
OUTPUT_DIR = "./tmp/output_image" + str(_id) + "/"
run_cmd("ls -l ./tmp/*/*")
run_cmd("rm -rf " + INPUT_DIR)
run_cmd("rm -rf " + OUTPUT_DIR)
run_cmd("mkdir -p " + INPUT_DIR)
run_cmd("mkdir -p " + OUTPUT_DIR)
img.save(INPUT_DIR + "1.png", "PNG")
if mode == "base":
run_cmd("python inference_realesrgan.py -n RealESRGAN_x4plus -i "+ INPUT_DIR + " -o " + OUTPUT_DIR)
else:
run_cmd("python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i "+ INPUT_DIR + " -o " + OUTPUT_DIR)
return os.path.join(OUTPUT_DIR, "1_out.png")
title = "Real-ESRGAN"
description = "Gradio demo for Real-ESRGAN. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below. Please click submit only once"
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2107.10833'>Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data</a> | <a href='https://github.com/xinntao/Real-ESRGAN'>Github Repo</a></p>"
gr.Interface(
inference,
[gr.inputs.Image(type="pil", label="Input"),gr.inputs.Radio(["base","anime"], type="value", default="anime", label="model type")],
gr.outputs.Image(type="file", label="Output"),
title=title,
description=description,
article=article
).launch() |