luca115 commited on
Commit
23553ba
·
verified ·
1 Parent(s): 3bbaf85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -3,6 +3,7 @@ import spaces
3
  from image_gen_aux import UpscaleWithModel
4
  from image_gen_aux.utils import load_image
5
  from fastapi.middleware.cors import CORSMiddleware
 
6
 
7
  MODELS = {
8
  "4xNomosWebPhotoRealPLKSR": "Phips/4xNomosWebPhoto_RealPLKSR",
@@ -12,7 +13,18 @@ MODELS = {
12
  }
13
 
14
 
15
- @spaces.GPU
 
 
 
 
 
 
 
 
 
 
 
16
  def upscale_image(image, model_selection):
17
  original = load_image(image)
18
 
 
3
  from image_gen_aux import UpscaleWithModel
4
  from image_gen_aux.utils import load_image
5
  from fastapi.middleware.cors import CORSMiddleware
6
+ import math
7
 
8
  MODELS = {
9
  "4xNomosWebPhotoRealPLKSR": "Phips/4xNomosWebPhoto_RealPLKSR",
 
13
  }
14
 
15
 
16
+ def get_duration(
17
+ image, model_selection
18
+ ):
19
+ height, width, _ = image.shape
20
+ megapixel = math.ceil((width * height) / 1_000_000)
21
+
22
+ if model_selection in ["4xNomosWebPhotoRealPLKSR", "4xRealESRGAN"]:
23
+ return int(megapixel * 10)
24
+ else:
25
+ return int(megapixel * 30)
26
+
27
+ @spaces.GPU(duration = get_duration)
28
  def upscale_image(image, model_selection):
29
  original = load_image(image)
30