climategan / app.py
NimaBoscarino's picture
Give perspective choice
5788d58
raw
history blame
2.06 kB
import os
import gradio as gr
import googlemaps
from skimage import io
from urllib import parse
from inferences import ClimateGAN
API_KEY = os.environ.get("API_KEY")
gmaps = googlemaps.Client(key=API_KEY)
model = ClimateGAN(model_path="config/model/masker")
def predict(place, perspective):
geocode_result = gmaps.geocode(place)
static_map_url = ""
if perspective == "A":
address = geocode_result[0]['formatted_address']
static_map_url = f"https://maps.googleapis.com/maps/api/streetview?size=640x640&location={parse.quote(address)}&source=outdoor&key={API_KEY}"
else:
loc = geocode_result[0]['geometry']['location']
static_map_url = f"https://maps.googleapis.com/maps/api/streetview?size=640x640&location={loc['lat']},{loc['lng']}&source=outdoor&key={API_KEY}"
img_np = io.imread(static_map_url)
flood, wildfire, smog = model.inference(img_np)
return img_np, flood, wildfire, smog
gr.Interface(
predict,
inputs=[
gr.inputs.Textbox(label="Address or place name"),
gr.inputs.Radio(["A", "B"], label="Perspective")
],
outputs=[
gr.outputs.Image(type="numpy", label="Original image"),
gr.outputs.Image(type="numpy", label="Flooding"),
gr.outputs.Image(type="numpy", label="Wildfire"),
gr.outputs.Image(type="numpy", label="Smog"),
],
title="ClimateGAN",
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.",
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>",
examples=[
["Vancouver Art Gallery", "A"],
["Chicago Bean", "B"],
["Duomo Siracusa", "A"],
],
css=".footer{display:none !important}",
).launch(cache_examples=True)