Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,7 +14,8 @@ import PIL
|
|
| 14 |
import PIL.Image
|
| 15 |
import PIL.ImageDraw
|
| 16 |
import PIL.ImageFont
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
logger = structlog.getLogger()
|
| 20 |
weather_api_key = os.environ['WEATHER_API']
|
|
@@ -179,23 +180,37 @@ class WeatherDraw:
|
|
| 179 |
logger.info(f"Got animal {animal}")
|
| 180 |
chat = Chat(f'''
|
| 181 |
Given the following weather conditions, write a plaintext, short, and vivid description of an
|
| 182 |
-
adorable {animal} in the weather conditions doing
|
| 183 |
Only write the short description and nothing else.
|
| 184 |
Do not include specific numbers.'''.replace('\n', ' '))
|
| 185 |
description = chat.message(str(weather_info))
|
| 186 |
prompt = f'{description}. Adorable, cute, 4k, Award winning, in the style of {random.choice(art_styles)}'
|
| 187 |
logger.info(prompt)
|
| 188 |
img = Image.create(prompt, **kwargs)
|
| 189 |
-
return img["b64_json"]
|
| 190 |
|
| 191 |
def step_one_forecast(self, weather_info, **kwargs):
|
| 192 |
-
img = self.generate_image(weather_info, **kwargs)
|
| 193 |
# text = self.clean_text(weather_info)
|
| 194 |
# return overlay_text_on_image(img, text, 'bottom-left')
|
| 195 |
-
return img
|
| 196 |
|
| 197 |
def step(self, zip_code='10001', **kwargs):
|
| 198 |
forecast = Weather(zip_code).get_info()
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
import PIL.Image
|
| 15 |
import PIL.ImageDraw
|
| 16 |
import PIL.ImageFont
|
| 17 |
+
import gradio as gr
|
| 18 |
+
|
| 19 |
|
| 20 |
logger = structlog.getLogger()
|
| 21 |
weather_api_key = os.environ['WEATHER_API']
|
|
|
|
| 180 |
logger.info(f"Got animal {animal}")
|
| 181 |
chat = Chat(f'''
|
| 182 |
Given the following weather conditions, write a plaintext, short, and vivid description of an
|
| 183 |
+
adorable {animal} in the weather conditions doing a human activity matching the weather.
|
| 184 |
Only write the short description and nothing else.
|
| 185 |
Do not include specific numbers.'''.replace('\n', ' '))
|
| 186 |
description = chat.message(str(weather_info))
|
| 187 |
prompt = f'{description}. Adorable, cute, 4k, Award winning, in the style of {random.choice(art_styles)}'
|
| 188 |
logger.info(prompt)
|
| 189 |
img = Image.create(prompt, **kwargs)
|
| 190 |
+
return img["b64_json"], prompt
|
| 191 |
|
| 192 |
def step_one_forecast(self, weather_info, **kwargs):
|
| 193 |
+
img, txt = self.generate_image(weather_info, **kwargs)
|
| 194 |
# text = self.clean_text(weather_info)
|
| 195 |
# return overlay_text_on_image(img, text, 'bottom-left')
|
| 196 |
+
return img, txt
|
| 197 |
|
| 198 |
def step(self, zip_code='10001', **kwargs):
|
| 199 |
forecast = Weather(zip_code).get_info()
|
| 200 |
+
images, texts = [], []
|
| 201 |
+
for time, data in forecast.items():
|
| 202 |
+
img, txt = overlay_text_on_image(self.step_one_forecast(data, **kwargs), time, 'top-right')
|
| 203 |
+
images.append(img)
|
| 204 |
+
texts.append(txt)
|
| 205 |
+
return create_collage(*images), *texts
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
# Define Gradio interface
|
| 209 |
+
iface = gr.Interface(fn=WeatherDraw().step,
|
| 210 |
+
inputs=gr.inputs.Text(label="Enter Zipcode"),
|
| 211 |
+
outputs=[gr.outputs.Image(), "text", "text", "text", "text"],
|
| 212 |
+
title="US Zipcode Weather",
|
| 213 |
+
description="Enter a US Zipcode and get some weather.")
|
| 214 |
+
|
| 215 |
+
# Run the interface
|
| 216 |
+
iface.launch()
|