PawinC commited on
Commit
381dd73
1 Parent(s): 9edf41a

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +21 -2
main.py CHANGED
@@ -5,6 +5,21 @@ from threading import Thread
5
  from dotenv import load_dotenv
6
  load_dotenv()
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  CLIENT_SECRET = os.environ['ClientSecret']
9
  TOKEN = os.environ['TestingToken']
10
  ADMINS = [766145655038410763, 937495666471628831]
@@ -210,8 +225,12 @@ async def on_message(message):
210
  await jobStatusMessage.edit(content=(statusTemplate.replace("%CURRENTSTEP%", "🧠 Upscaling")+"\nThis may take a while..."))
211
  #os.system(execute_upscale)
212
  #subprocess.run(execute_upscale, shell=True)
213
- upscaleProcess = await asyncio.create_subprocess_shell(execute_upscale)
214
- await upscaleProcess.wait()
 
 
 
 
215
 
216
  uendtime = perf_counter()
217
 
 
5
  from dotenv import load_dotenv
6
  load_dotenv()
7
 
8
+ import torch
9
+ from PIL import Image
10
+ import numpy as np
11
+ from RealESRGAN import RealESRGAN
12
+
13
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
14
+
15
+ model = RealESRGAN(device, scale=4)
16
+ model.load_weights('weights/RealESRGAN_x4.pth', download=True)
17
+
18
+ async def do_upscale(infile, outfile):
19
+ image = Image.open(infile).convert('RGB')
20
+ sr_image = model.predict(image)
21
+ sr_image.save(outfile)
22
+
23
  CLIENT_SECRET = os.environ['ClientSecret']
24
  TOKEN = os.environ['TestingToken']
25
  ADMINS = [766145655038410763, 937495666471628831]
 
225
  await jobStatusMessage.edit(content=(statusTemplate.replace("%CURRENTSTEP%", "🧠 Upscaling")+"\nThis may take a while..."))
226
  #os.system(execute_upscale)
227
  #subprocess.run(execute_upscale, shell=True)
228
+
229
+
230
+ # upscaleProcess = await asyncio.create_subprocess_shell(execute_upscale)
231
+ # await upscaleProcess.wait()
232
+
233
+ await do_upscale(inputfile, outputpng)
234
 
235
  uendtime = perf_counter()
236