Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,6 +18,7 @@ import PIL.ImageFont
|
|
| 18 |
import gradio as gr
|
| 19 |
import cachetools.func
|
| 20 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 21 |
|
| 22 |
|
| 23 |
logger = structlog.getLogger()
|
|
@@ -126,6 +127,19 @@ class Image:
|
|
| 126 |
if n == 1: return resp["data"][0]
|
| 127 |
return resp["data"]
|
| 128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
def overlay_text_on_image(img, text, position, text_color=(255, 255, 255), box_color=(0, 0, 0, 128), decode=False):
|
| 131 |
# Convert the base64 string back to an image
|
|
@@ -206,10 +220,15 @@ Do not include specific numbers.'''.replace('\n', ' '))
|
|
| 206 |
def step(self, zip_code='10001', **kwargs):
|
| 207 |
forecast = Weather(zip_code).get_info()
|
| 208 |
images, texts = [], []
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
return create_collage(*images), *texts
|
| 214 |
|
| 215 |
|
|
|
|
| 18 |
import gradio as gr
|
| 19 |
import cachetools.func
|
| 20 |
from huggingface_hub import hf_hub_download
|
| 21 |
+
import concurrent.futures
|
| 22 |
|
| 23 |
|
| 24 |
logger = structlog.getLogger()
|
|
|
|
| 127 |
if n == 1: return resp["data"][0]
|
| 128 |
return resp["data"]
|
| 129 |
|
| 130 |
+
def create_collage(image1, image2, image3, image4):
|
| 131 |
+
# assuming images are the same size
|
| 132 |
+
width, height = image1.size
|
| 133 |
+
|
| 134 |
+
new_img = PIL.Image.new('RGB', (2 * width, 2 * height))
|
| 135 |
+
|
| 136 |
+
# place images in collage image
|
| 137 |
+
new_img.paste(image1, (0,0))
|
| 138 |
+
new_img.paste(image2, (width, 0))
|
| 139 |
+
new_img.paste(image3, (0, height))
|
| 140 |
+
new_img.paste(image4, (width, height))
|
| 141 |
+
|
| 142 |
+
return new_img
|
| 143 |
|
| 144 |
def overlay_text_on_image(img, text, position, text_color=(255, 255, 255), box_color=(0, 0, 0, 128), decode=False):
|
| 145 |
# Convert the base64 string back to an image
|
|
|
|
| 220 |
def step(self, zip_code='10001', **kwargs):
|
| 221 |
forecast = Weather(zip_code).get_info()
|
| 222 |
images, texts = [], []
|
| 223 |
+
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as e:
|
| 224 |
+
runs = {}
|
| 225 |
+
for time, data in forecast.items():
|
| 226 |
+
runs[e.submit(self.step_one_forecast, data, **kwargs)] = time, data
|
| 227 |
+
for r in concurrent.futures.as_completed(runs.keys()):
|
| 228 |
+
img, txt = r.result()
|
| 229 |
+
time, data = runs[r]
|
| 230 |
+
images.append(overlay_text_on_image(img, time, 'top-right', decode=True))
|
| 231 |
+
texts.append(txt)
|
| 232 |
return create_collage(*images), *texts
|
| 233 |
|
| 234 |
|