FCameCode commited on
Commit
3835b5a
·
1 Parent(s): 8c905ae

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -98
app.py DELETED
@@ -1,98 +0,0 @@
1
- import gradio as gr
2
- import numpy as np
3
- from math import ceil
4
- from huggingface_hub import from_pretrained_keras
5
- import requests
6
-
7
- x = requests.get(
8
- 'https://api.nasa.gov/planetary/apod?api_key=0eyGPKWmJmE5Z0Ijx25oG56ydbTKWE2H75xuEefx')
9
-
10
- print(x.url)
11
-
12
- model = from_pretrained_keras("GIanlucaRub/autoencoder_model_d_0")
13
-
14
-
15
- def double_res(input_image):
16
- input_height = input_image.shape[0]
17
- input_width = input_image.shape[1]
18
- height = ceil(input_height/128)
19
- width = ceil(input_width/128)
20
- expanded_input_image = np.zeros((128*height, 128*width, 3), dtype=np.uint8)
21
- np.copyto(expanded_input_image[0:input_height, 0:input_width], input_image)
22
-
23
- output_image = np.zeros((128*height*2, 128*width*2, 3), dtype=np.float32)
24
-
25
- for i in range(height):
26
- for j in range(width):
27
- temp_slice = expanded_input_image[i *
28
- 128:(i+1)*128, j*128:(j+1)*128]/255
29
- upsampled_slice = model.predict(temp_slice[np.newaxis, ...])
30
- np.copyto(output_image[i*256:(i+1)*256, j *
31
- 256:(j+1)*256], upsampled_slice[0])
32
- if i != 0 and j != 0 and i != height-1 and j != width-1:
33
- # removing inner borders
34
- right_slice = expanded_input_image[i *
35
- 128:(i+1)*128, (j+1)*128-64:(j+1)*128+64]/255
36
- right_upsampled_slice = model.predict(
37
- right_slice[np.newaxis, ...])
38
- resized_right_slice = right_upsampled_slice[0][64:192, 64:192]
39
- np.copyto(output_image[i*256+64:(i+1)*256-64,
40
- (j+1)*256-64:(j+1)*256+64], resized_right_slice)
41
-
42
- left_slice = expanded_input_image[i *
43
- 128:(i+1)*128, j*128-64:(j)*128+64]/255
44
- left_upsampled_slice = model.predict(
45
- left_slice[np.newaxis, ...])
46
- resized_left_slice = left_upsampled_slice[0][64:192, 64:192]
47
- np.copyto(output_image[i*256+64:(i+1)*256-64,
48
- j*256-64:j*256+64], resized_left_slice)
49
-
50
- upper_slice = expanded_input_image[(
51
- i+1)*128-64:(i+1)*128+64, j*128:(j+1)*128]/255
52
- upper_upsampled_slice = model.predict(
53
- upper_slice[np.newaxis, ...])
54
- resized_upper_slice = upper_upsampled_slice[0][64:192, 64:192]
55
- np.copyto(output_image[(i+1)*256-64:(i+1)*256+64,
56
- j*256+64:(j+1)*256-64], resized_upper_slice)
57
-
58
- lower_slice = expanded_input_image[i *
59
- 128-64:i*128+64, j*128:(j+1)*128]/255
60
- lower_upsampled_slice = model.predict(
61
- lower_slice[np.newaxis, ...])
62
- resized_lower_slice = lower_upsampled_slice[0][64:192, 64:192]
63
- np.copyto(output_image[i*256-64:i*256+64,
64
- j*256+64:(j+1)*256-64], resized_lower_slice)
65
-
66
-
67
- # removing angles
68
- lower_right_slice = expanded_input_image[i *
69
- 128-64:i*128+64, (j+1)*128-64:(j+1)*128+64]/255
70
- lower_right_upsampled_slice = model.predict(
71
- lower_right_slice[np.newaxis, ...])
72
- resized_lower_right_slice = lower_right_upsampled_slice[0][64:192, 64:192]
73
- np.copyto(output_image[i*256-64:i*256+64, (j+1)
74
- * 256-64:(j+1)*256+64], resized_lower_right_slice)
75
-
76
- lower_left_slice = expanded_input_image[i *
77
- 128-64:i*128+64, j*128-64:j*128+64]/255
78
- lower_left_upsampled_slice = model.predict(
79
- lower_left_slice[np.newaxis, ...])
80
- resized_lower_left_slice = lower_left_upsampled_slice[0][64:192, 64:192]
81
- np.copyto(
82
- output_image[i*256-64:i*256+64, j*256-64:j*256+64], resized_lower_left_slice)
83
-
84
- resized_output_image = output_image[0:input_height*2, 0:input_width*2]
85
- return resized_output_image
86
-
87
-
88
- demo = gr.Interface(
89
- fn=double_res,
90
- title="Double picture resolution",
91
- description="Upload a picture and get the horizontal and vertical resolution doubled (4x pixels)",
92
- allow_flagging="never",
93
- inputs=[
94
- gr.inputs.Image(type="numpy")
95
- ],
96
- outputs=gr.Image(type="numpy"))
97
-
98
- demo.launch()