Spaces:
Runtime error
Runtime error
Commit
·
5788d58
1
Parent(s):
ee454f2
Give perspective choice
Browse files
app.py
CHANGED
|
@@ -2,17 +2,24 @@ import os
|
|
| 2 |
import gradio as gr
|
| 3 |
import googlemaps
|
| 4 |
from skimage import io
|
| 5 |
-
|
| 6 |
from inferences import ClimateGAN
|
| 7 |
|
| 8 |
API_KEY = os.environ.get("API_KEY")
|
| 9 |
gmaps = googlemaps.Client(key=API_KEY)
|
| 10 |
model = ClimateGAN(model_path="config/model/masker")
|
| 11 |
|
| 12 |
-
def predict(place):
|
| 13 |
geocode_result = gmaps.geocode(place)
|
| 14 |
-
|
| 15 |
-
static_map_url =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
img_np = io.imread(static_map_url)
|
| 18 |
flood, wildfire, smog = model.inference(img_np)
|
|
@@ -22,7 +29,8 @@ def predict(place):
|
|
| 22 |
gr.Interface(
|
| 23 |
predict,
|
| 24 |
inputs=[
|
| 25 |
-
gr.inputs.Textbox(label="Address or place name")
|
|
|
|
| 26 |
],
|
| 27 |
outputs=[
|
| 28 |
gr.outputs.Image(type="numpy", label="Original image"),
|
|
@@ -31,12 +39,12 @@ gr.Interface(
|
|
| 31 |
gr.outputs.Image(type="numpy", label="Smog"),
|
| 32 |
],
|
| 33 |
title="ClimateGAN",
|
| 34 |
-
description="Enter an address or place name, and ClimateGAN will generate images showing how the location could be impacted by flooding, wildfires, or smog.",
|
| 35 |
article="<p style='text-align: center'>This project is a clone of <a href='https://thisclimatedoesnotexist.com/'>ThisClimateDoesNotExist</a> | <a href='https://github.com/cc-ai/climategan'>ClimateGAN GitHub Repo</a></p>",
|
| 36 |
examples=[
|
| 37 |
-
"Vancouver Art Gallery",
|
| 38 |
-
"Chicago Bean",
|
| 39 |
-
"Duomo Siracusa"
|
| 40 |
],
|
| 41 |
css=".footer{display:none !important}",
|
| 42 |
).launch(cache_examples=True)
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import googlemaps
|
| 4 |
from skimage import io
|
| 5 |
+
from urllib import parse
|
| 6 |
from inferences import ClimateGAN
|
| 7 |
|
| 8 |
API_KEY = os.environ.get("API_KEY")
|
| 9 |
gmaps = googlemaps.Client(key=API_KEY)
|
| 10 |
model = ClimateGAN(model_path="config/model/masker")
|
| 11 |
|
| 12 |
+
def predict(place, perspective):
|
| 13 |
geocode_result = gmaps.geocode(place)
|
| 14 |
+
|
| 15 |
+
static_map_url = ""
|
| 16 |
+
|
| 17 |
+
if perspective == "A":
|
| 18 |
+
address = geocode_result[0]['formatted_address']
|
| 19 |
+
static_map_url = f"https://maps.googleapis.com/maps/api/streetview?size=640x640&location={parse.quote(address)}&source=outdoor&key={API_KEY}"
|
| 20 |
+
else:
|
| 21 |
+
loc = geocode_result[0]['geometry']['location']
|
| 22 |
+
static_map_url = f"https://maps.googleapis.com/maps/api/streetview?size=640x640&location={loc['lat']},{loc['lng']}&source=outdoor&key={API_KEY}"
|
| 23 |
|
| 24 |
img_np = io.imread(static_map_url)
|
| 25 |
flood, wildfire, smog = model.inference(img_np)
|
|
|
|
| 29 |
gr.Interface(
|
| 30 |
predict,
|
| 31 |
inputs=[
|
| 32 |
+
gr.inputs.Textbox(label="Address or place name"),
|
| 33 |
+
gr.inputs.Radio(["A", "B"], label="Perspective")
|
| 34 |
],
|
| 35 |
outputs=[
|
| 36 |
gr.outputs.Image(type="numpy", label="Original image"),
|
|
|
|
| 39 |
gr.outputs.Image(type="numpy", label="Smog"),
|
| 40 |
],
|
| 41 |
title="ClimateGAN",
|
| 42 |
+
description="Enter an address or place name, and ClimateGAN will generate images showing how the location could be impacted by flooding, wildfires, or smog. Changing the \"perspective\" will give you a different image of the same location.",
|
| 43 |
article="<p style='text-align: center'>This project is a clone of <a href='https://thisclimatedoesnotexist.com/'>ThisClimateDoesNotExist</a> | <a href='https://github.com/cc-ai/climategan'>ClimateGAN GitHub Repo</a></p>",
|
| 44 |
examples=[
|
| 45 |
+
["Vancouver Art Gallery", "A"],
|
| 46 |
+
["Chicago Bean", "B"],
|
| 47 |
+
["Duomo Siracusa", "A"],
|
| 48 |
],
|
| 49 |
css=".footer{display:none !important}",
|
| 50 |
).launch(cache_examples=True)
|