NimaBoscarino commited on
Commit
4b2459f
1 Parent(s): 5bc2e95

gradio init

Browse files
Files changed (1) hide show
  1. app.py +44 -1
app.py CHANGED
@@ -1,7 +1,50 @@
1
  import os
 
 
 
 
 
2
  os.system('gdown https://drive.google.com/u/0/uc?id=18OCUIy7JQ2Ow_-cC5xn_hhDn-Bp45N1K')
3
  os.system('unzip release-github-v1.zip')
4
  os.system('mkdir config')
5
  os.system('mv model config')
6
- os.system('python apply_events.py -b 1 -i ./inputs -r config/model/masker --output_path ./outputs --overwrite')
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
+ import gradio as gr
3
+ import googlemaps
4
+ import requests
5
+ from PIL import Image
6
+
7
  os.system('gdown https://drive.google.com/u/0/uc?id=18OCUIy7JQ2Ow_-cC5xn_hhDn-Bp45N1K')
8
  os.system('unzip release-github-v1.zip')
9
  os.system('mkdir config')
10
  os.system('mv model config')
 
11
 
12
+ API_KEY = os.environ.get("API_KEY")
13
+ gmaps = googlemaps.Client(key=API_KEY)
14
+
15
+ def predict(place):
16
+ # 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)
17
+ geocode_result = gmaps.geocode(place)
18
+ loc = geocode_result[0]['geometry']['location']
19
+ 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}"
20
+
21
+ response = requests.get(static_map_url)
22
+ img = response.content
23
+
24
+ file = open("./inputs/loc_image.png", "wb")
25
+ file.write(response.content)
26
+ file.close()
27
+
28
+ # Next improvement is to refactor apply_events so that I can load the model in memory when the interface launces
29
+ # Would save ~10 seconds according to the logs.
30
+ # 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.
31
+ os.system('python apply_events.py -b 1 -i ./inputs -r config/model/masker --output_path ./outputs --overwrite')
32
+
33
+ # Also if I refactor then I wouldn't have to read from the filesystem...
34
+ # I would like to show all three images
35
+ os.system('ls -R ./outputs')
36
+ return False # currently broken
37
+
38
+
39
+ gr.Interface(
40
+ predict,
41
+ inputs=[
42
+ gr.inputs.Textbox(label="Address or place name")
43
+ ],
44
+ outputs="image",
45
+ title="ClimateGAN",
46
+ # description="These CryptoPunks do not exist. Generate random punks with an initial seed!",
47
+ # 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
48
+ # examples=[[123, 15], [42, 29], [456, 8], [1337, 35]],
49
+ # css=".footer{display:none !important}",
50
+ ).launch(cache_examples=True)