Spaces:
Runtime error
Runtime error
add gradio code
Browse filesSigned-off-by: Samhita Alla <aallasamhita@gmail.com>
- README.md +1 -1
- app.py +136 -0
- data/test/greece.jpg +0 -0
- log.csv +2 -0
- requirements.in +5 -0
- requirements.txt +176 -0
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
title: Geolocator
|
3 |
-
emoji:
|
4 |
colorFrom: yellow
|
5 |
colorTo: red
|
6 |
sdk: gradio
|
|
|
1 |
---
|
2 |
title: Geolocator
|
3 |
+
emoji: π
|
4 |
colorFrom: yellow
|
5 |
colorTo: red
|
6 |
sdk: gradio
|
app.py
ADDED
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import mimetypes
|
3 |
+
import os
|
4 |
+
from typing import Tuple
|
5 |
+
|
6 |
+
import gradio as gr
|
7 |
+
import pandas as pd
|
8 |
+
import plotly
|
9 |
+
import plotly.express as px
|
10 |
+
import requests
|
11 |
+
from dotenv import load_dotenv
|
12 |
+
|
13 |
+
load_dotenv()
|
14 |
+
|
15 |
+
URL = os.getenv("ENDPOINT")
|
16 |
+
|
17 |
+
|
18 |
+
def get_plotly_graph(
|
19 |
+
latitude: float, longitude: float, location: str
|
20 |
+
) -> plotly.graph_objects.Figure:
|
21 |
+
lat_long_data = [[latitude, longitude, location]]
|
22 |
+
map_df = pd.DataFrame(lat_long_data, columns=["latitude", "longitude", "location"])
|
23 |
+
|
24 |
+
px.set_mapbox_access_token(os.getenv("MAPBOX_TOKEN"))
|
25 |
+
fig = px.scatter_mapbox(
|
26 |
+
map_df,
|
27 |
+
lat="latitude",
|
28 |
+
lon="longitude",
|
29 |
+
hover_name="location",
|
30 |
+
color_discrete_sequence=["fuchsia"],
|
31 |
+
zoom=5,
|
32 |
+
height=300,
|
33 |
+
)
|
34 |
+
fig.update_layout(mapbox_style="dark")
|
35 |
+
fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
|
36 |
+
return fig
|
37 |
+
|
38 |
+
|
39 |
+
def image_gradio(img_file: str) -> Tuple[str, plotly.graph_objects.Figure]:
|
40 |
+
data = json.loads(
|
41 |
+
requests.post(
|
42 |
+
f"{URL}predict-image",
|
43 |
+
files={
|
44 |
+
"image": (
|
45 |
+
img_file,
|
46 |
+
open(img_file, "rb"),
|
47 |
+
mimetypes.guess_type(img_file)[0],
|
48 |
+
)
|
49 |
+
},
|
50 |
+
).text
|
51 |
+
)
|
52 |
+
|
53 |
+
location = data["location"]
|
54 |
+
return data["location"], get_plotly_graph(
|
55 |
+
latitude=data["latitude"], longitude=data["longitude"], location=location
|
56 |
+
)
|
57 |
+
|
58 |
+
|
59 |
+
def video_gradio(video_file: str) -> Tuple[str, plotly.graph_objects.Figure]:
|
60 |
+
data = json.loads(
|
61 |
+
requests.post(
|
62 |
+
f"{URL}predict-video",
|
63 |
+
files={
|
64 |
+
"video": (
|
65 |
+
video_file,
|
66 |
+
open(video_file, "rb"),
|
67 |
+
"application/octet-stream",
|
68 |
+
)
|
69 |
+
},
|
70 |
+
).text
|
71 |
+
)
|
72 |
+
|
73 |
+
location = data["location"]
|
74 |
+
return location, get_plotly_graph(
|
75 |
+
latitude=data["latitude"], longitude=data["longitude"], location=location
|
76 |
+
)
|
77 |
+
|
78 |
+
|
79 |
+
def url_gradio(url: str) -> Tuple[str, plotly.graph_objects.Figure]:
|
80 |
+
data = json.loads(
|
81 |
+
requests.post(
|
82 |
+
f"{URL}predict-url",
|
83 |
+
headers={"content-type": "text/plain"},
|
84 |
+
data=url,
|
85 |
+
).text
|
86 |
+
)
|
87 |
+
|
88 |
+
location = data["location"]
|
89 |
+
return location, get_plotly_graph(
|
90 |
+
latitude=data["latitude"], longitude=data["longitude"], location=location
|
91 |
+
)
|
92 |
+
|
93 |
+
|
94 |
+
with gr.Blocks() as demo:
|
95 |
+
gr.Markdown("# GeoLocator")
|
96 |
+
gr.Markdown(
|
97 |
+
"## An app that guesses the location of an image π, a video πΉ or a YouTube link π."
|
98 |
+
)
|
99 |
+
gr.Markdown(
|
100 |
+
"Find the code powering this application [here](https://github.com/samhita-alla/geolocator)."
|
101 |
+
)
|
102 |
+
with gr.Tab("Image"):
|
103 |
+
with gr.Row():
|
104 |
+
img_input = gr.Image(type="filepath", label="im")
|
105 |
+
with gr.Column():
|
106 |
+
img_text_output = gr.Textbox(label="Location")
|
107 |
+
img_plot = gr.Plot()
|
108 |
+
img_text_button = gr.Button("Go locate!")
|
109 |
+
with gr.Tab("Video"):
|
110 |
+
with gr.Row():
|
111 |
+
video_input = gr.Video(type="filepath", label="video")
|
112 |
+
with gr.Column():
|
113 |
+
video_text_output = gr.Textbox(label="Location")
|
114 |
+
video_plot = gr.Plot()
|
115 |
+
video_text_button = gr.Button("Go locate!")
|
116 |
+
with gr.Tab("YouTube Link"):
|
117 |
+
with gr.Row():
|
118 |
+
url_input = gr.Textbox(label="YouTube video link")
|
119 |
+
with gr.Column():
|
120 |
+
url_text_output = gr.Textbox(label="Location")
|
121 |
+
url_plot = gr.Plot()
|
122 |
+
url_text_button = gr.Button("Go locate!")
|
123 |
+
|
124 |
+
img_text_button.click(
|
125 |
+
image_gradio, inputs=img_input, outputs=[img_text_output, img_plot]
|
126 |
+
)
|
127 |
+
video_text_button.click(
|
128 |
+
video_gradio, inputs=video_input, outputs=[video_text_output, video_plot]
|
129 |
+
)
|
130 |
+
url_text_button.click(
|
131 |
+
url_gradio, inputs=url_input, outputs=[url_text_output, url_plot]
|
132 |
+
)
|
133 |
+
|
134 |
+
examples = gr.Examples(".", inputs=[img_input, url_input])
|
135 |
+
|
136 |
+
demo.launch()
|
data/test/greece.jpg
ADDED
log.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
im,text
|
2 |
+
"data/test/greece.jpg","https://www.youtube.com/watch?v=wxeQkJTZrsw"
|
requirements.in
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
pandas
|
3 |
+
plotly
|
4 |
+
requests
|
5 |
+
python-dotenv
|
requirements.txt
ADDED
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# This file is autogenerated by pip-compile with python 3.9
|
3 |
+
# To update, run:
|
4 |
+
#
|
5 |
+
# pip-compile --output-file=gradio_requirements.txt gradio_requirements.in
|
6 |
+
#
|
7 |
+
aiohttp==3.8.3
|
8 |
+
# via gradio
|
9 |
+
aiosignal==1.2.0
|
10 |
+
# via aiohttp
|
11 |
+
anyio==3.6.1
|
12 |
+
# via
|
13 |
+
# httpcore
|
14 |
+
# starlette
|
15 |
+
async-timeout==4.0.2
|
16 |
+
# via aiohttp
|
17 |
+
attrs==22.1.0
|
18 |
+
# via aiohttp
|
19 |
+
bcrypt==4.0.1
|
20 |
+
# via paramiko
|
21 |
+
certifi==2022.9.24
|
22 |
+
# via
|
23 |
+
# httpcore
|
24 |
+
# httpx
|
25 |
+
# requests
|
26 |
+
cffi==1.15.1
|
27 |
+
# via
|
28 |
+
# cryptography
|
29 |
+
# pynacl
|
30 |
+
charset-normalizer==2.1.1
|
31 |
+
# via
|
32 |
+
# aiohttp
|
33 |
+
# requests
|
34 |
+
click==8.1.3
|
35 |
+
# via uvicorn
|
36 |
+
contourpy==1.0.5
|
37 |
+
# via matplotlib
|
38 |
+
cryptography==38.0.1
|
39 |
+
# via paramiko
|
40 |
+
cycler==0.11.0
|
41 |
+
# via matplotlib
|
42 |
+
fastapi==0.85.0
|
43 |
+
# via gradio
|
44 |
+
ffmpy==0.3.0
|
45 |
+
# via gradio
|
46 |
+
fonttools==4.37.4
|
47 |
+
# via matplotlib
|
48 |
+
frozenlist==1.3.1
|
49 |
+
# via
|
50 |
+
# aiohttp
|
51 |
+
# aiosignal
|
52 |
+
fsspec==2022.8.2
|
53 |
+
# via gradio
|
54 |
+
gradio==3.4.1
|
55 |
+
# via -r gradio_requirements.in
|
56 |
+
h11==0.12.0
|
57 |
+
# via
|
58 |
+
# gradio
|
59 |
+
# httpcore
|
60 |
+
# uvicorn
|
61 |
+
httpcore==0.15.0
|
62 |
+
# via httpx
|
63 |
+
httpx==0.23.0
|
64 |
+
# via gradio
|
65 |
+
idna==3.4
|
66 |
+
# via
|
67 |
+
# anyio
|
68 |
+
# requests
|
69 |
+
# rfc3986
|
70 |
+
# yarl
|
71 |
+
jinja2==3.1.2
|
72 |
+
# via gradio
|
73 |
+
kiwisolver==1.4.4
|
74 |
+
# via matplotlib
|
75 |
+
linkify-it-py==1.0.3
|
76 |
+
# via markdown-it-py
|
77 |
+
markdown-it-py[linkify,plugins]==2.1.0
|
78 |
+
# via
|
79 |
+
# gradio
|
80 |
+
# mdit-py-plugins
|
81 |
+
markupsafe==2.1.1
|
82 |
+
# via jinja2
|
83 |
+
matplotlib==3.6.1
|
84 |
+
# via gradio
|
85 |
+
mdit-py-plugins==0.3.1
|
86 |
+
# via markdown-it-py
|
87 |
+
mdurl==0.1.2
|
88 |
+
# via markdown-it-py
|
89 |
+
multidict==6.0.2
|
90 |
+
# via
|
91 |
+
# aiohttp
|
92 |
+
# yarl
|
93 |
+
numpy==1.23.3
|
94 |
+
# via
|
95 |
+
# contourpy
|
96 |
+
# gradio
|
97 |
+
# matplotlib
|
98 |
+
# pandas
|
99 |
+
orjson==3.8.0
|
100 |
+
# via gradio
|
101 |
+
packaging==21.3
|
102 |
+
# via matplotlib
|
103 |
+
pandas==1.5.0
|
104 |
+
# via
|
105 |
+
# -r gradio_requirements.in
|
106 |
+
# gradio
|
107 |
+
paramiko==2.11.0
|
108 |
+
# via gradio
|
109 |
+
pillow==9.2.0
|
110 |
+
# via
|
111 |
+
# gradio
|
112 |
+
# matplotlib
|
113 |
+
plotly==5.10.0
|
114 |
+
# via -r gradio_requirements.in
|
115 |
+
pycparser==2.21
|
116 |
+
# via cffi
|
117 |
+
pycryptodome==3.15.0
|
118 |
+
# via gradio
|
119 |
+
pydantic==1.10.2
|
120 |
+
# via
|
121 |
+
# fastapi
|
122 |
+
# gradio
|
123 |
+
pydub==0.25.1
|
124 |
+
# via gradio
|
125 |
+
pynacl==1.5.0
|
126 |
+
# via paramiko
|
127 |
+
pyparsing==3.0.9
|
128 |
+
# via
|
129 |
+
# matplotlib
|
130 |
+
# packaging
|
131 |
+
python-dateutil==2.8.2
|
132 |
+
# via
|
133 |
+
# matplotlib
|
134 |
+
# pandas
|
135 |
+
python-dotenv==0.21.0
|
136 |
+
# via -r gradio_requirements.in
|
137 |
+
python-multipart==0.0.5
|
138 |
+
# via gradio
|
139 |
+
pytz==2022.4
|
140 |
+
# via pandas
|
141 |
+
pyyaml==6.0
|
142 |
+
# via gradio
|
143 |
+
requests==2.28.1
|
144 |
+
# via
|
145 |
+
# -r gradio_requirements.in
|
146 |
+
# gradio
|
147 |
+
rfc3986[idna2008]==1.5.0
|
148 |
+
# via httpx
|
149 |
+
six==1.16.0
|
150 |
+
# via
|
151 |
+
# paramiko
|
152 |
+
# python-dateutil
|
153 |
+
# python-multipart
|
154 |
+
sniffio==1.3.0
|
155 |
+
# via
|
156 |
+
# anyio
|
157 |
+
# httpcore
|
158 |
+
# httpx
|
159 |
+
starlette==0.20.4
|
160 |
+
# via fastapi
|
161 |
+
tenacity==8.1.0
|
162 |
+
# via plotly
|
163 |
+
typing-extensions==4.4.0
|
164 |
+
# via
|
165 |
+
# pydantic
|
166 |
+
# starlette
|
167 |
+
uc-micro-py==1.0.1
|
168 |
+
# via linkify-it-py
|
169 |
+
urllib3==1.26.12
|
170 |
+
# via requests
|
171 |
+
uvicorn==0.18.3
|
172 |
+
# via gradio
|
173 |
+
websockets==10.3
|
174 |
+
# via gradio
|
175 |
+
yarl==1.8.1
|
176 |
+
# via aiohttp
|