Spaces:
Runtime error
Runtime error
GIanlucaRub
commited on
Commit
•
e547f95
1
Parent(s):
bf2031a
Update app.py
Browse files
app.py
CHANGED
@@ -7,10 +7,10 @@ import numpy as np
|
|
7 |
from math import ceil
|
8 |
from huggingface_hub import from_pretrained_keras
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
result = r.json()
|
15 |
receive = requests.get(result['url'])
|
16 |
img = Image.open(BytesIO(receive.content)).convert('RGB')
|
@@ -93,7 +93,11 @@ def double_res(input_image):
|
|
93 |
return resized_output_image
|
94 |
|
95 |
def get_new_img():
|
96 |
-
|
|
|
|
|
|
|
|
|
97 |
numpydata = asarray(original_img)
|
98 |
doubled_img = double_res(numpydata) # numpy.ndarray
|
99 |
return original_img,doubled_img
|
@@ -106,10 +110,10 @@ with gr.Blocks() as demo:
|
|
106 |
gr.Label("Original image")
|
107 |
original = gr.Image(original_img)
|
108 |
with gr.Column():
|
109 |
-
gr.Label("Image with resolution
|
110 |
doubled = gr.Image(doubled_img)
|
111 |
-
with gr.Row()
|
112 |
btn_get = gr.Button("Get the new daily image")
|
113 |
# Event
|
114 |
btn_get.click(get_new_img, inputs=None, outputs = [original,doubled])
|
115 |
-
demo.launch()
|
|
|
7 |
from math import ceil
|
8 |
from huggingface_hub import from_pretrained_keras
|
9 |
|
10 |
+
api_key = 'https://api.nasa.gov/planetary/apod?api_key=0eyGPKWmJmE5Z0Ijx25oG56ydbTKWE2H75xuEefx'
|
11 |
+
date = '&date=2022-12-20'
|
12 |
+
def getRequest(date):
|
13 |
+
r = requests.get(api_key + date)
|
14 |
result = r.json()
|
15 |
receive = requests.get(result['url'])
|
16 |
img = Image.open(BytesIO(receive.content)).convert('RGB')
|
|
|
93 |
return resized_output_image
|
94 |
|
95 |
def get_new_img():
|
96 |
+
# sometimes the new image is a video
|
97 |
+
try:
|
98 |
+
original_img = getRequest('')
|
99 |
+
except:
|
100 |
+
original_img = getRequest(date)
|
101 |
numpydata = asarray(original_img)
|
102 |
doubled_img = double_res(numpydata) # numpy.ndarray
|
103 |
return original_img,doubled_img
|
|
|
110 |
gr.Label("Original image")
|
111 |
original = gr.Image(original_img)
|
112 |
with gr.Column():
|
113 |
+
gr.Label("Image with doubled resolution")
|
114 |
doubled = gr.Image(doubled_img)
|
115 |
+
with gr.Row():
|
116 |
btn_get = gr.Button("Get the new daily image")
|
117 |
# Event
|
118 |
btn_get.click(get_new_img, inputs=None, outputs = [original,doubled])
|
119 |
+
demo.launch()
|