File size: 2,263 Bytes
2096159
4b2459f
 
 
 
 
2096159
 
5bc2e95
 
6e601ed
4b2459f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
import gradio as gr
import googlemaps
import requests
from PIL import Image

os.system('gdown https://drive.google.com/u/0/uc?id=18OCUIy7JQ2Ow_-cC5xn_hhDn-Bp45N1K')
os.system('unzip release-github-v1.zip')
os.system('mkdir config')
os.system('mv model config')

API_KEY = os.environ.get("API_KEY")
gmaps = googlemaps.Client(key=API_KEY)

def predict(place):
    # I don't think I need to do any error handling, I'll just let Gradio manage it. (Test it with a bad place though)
    geocode_result = gmaps.geocode(place)
    loc = geocode_result[0]['geometry']['location']
    static_map_url = f"https://maps.googleapis.com/maps/api/streetview?size=400x400&location={loc['=lat']},{loc['lng']}&fov=80&heading=70&pitch=0&key={API_KEY}"

    response = requests.get(static_map_url)
    img = response.content

    file = open("./inputs/loc_image.png", "wb")
    file.write(response.content)
    file.close()

    # Next improvement is to refactor apply_events so that I can load the model in memory when the interface launces
    # Would save ~10 seconds according to the logs.
    # I would also like to not have to write the image to the filesystem, and instead just hold it in memory. As it is right now it would mess up with more than one person using it.
    os.system('python apply_events.py -b 1 -i ./inputs -r config/model/masker --output_path ./outputs --overwrite')

    # Also if I refactor then I wouldn't have to read from the filesystem...
    # I would like to show all three images
    os.system('ls -R ./outputs')
    return False  # currently broken


gr.Interface(
    predict,
    inputs=[
        gr.inputs.Textbox(label="Address or place name")
    ],
    outputs="image",
    title="ClimateGAN",
    # description="These CryptoPunks do not exist. Generate random punks with an initial seed!",
    # article="<p style='text-align: center'><a href='https://arxiv.org/pdf/1511.06434.pdf'>Unsupervised Representation Learning with Deep Convolutional Generative Adversarial Networks</a> | <a href='https://github.com/teddykoker/cryptopunks-gan'>Github Repo</a></p>",   ---- should be ClimateGAN citation
    # examples=[[123, 15], [42, 29], [456, 8], [1337, 35]],
    # css=".footer{display:none !important}",
).launch(cache_examples=True)