NemesisAlm commited on
Commit
401f7f3
β€’
1 Parent(s): 65cf4d0

Add application files

Browse files
Files changed (7) hide show
  1. README.md +2 -8
  2. app.py +46 -0
  3. croatia.jpg +0 -0
  4. favicon.ico +0 -0
  5. logo.jpg +0 -0
  6. requirements.txt +4 -0
  7. turkey.jpg +0 -0
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: GeolocationCountryClassification
3
- emoji: πŸ“Š
4
- colorFrom: red
5
- colorTo: pink
6
  sdk: gradio
7
  sdk_version: 3.41.2
8
- app_file: app.py
9
- pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: StreetClip_-_countries
3
+ app_file: app.py
 
 
4
  sdk: gradio
5
  sdk_version: 3.41.2
 
 
6
  ---
 
 
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+ import torch
3
+ from transformers import CLIPProcessor, CLIPModel
4
+ import gradio as gr
5
+
6
+ model = CLIPModel.from_pretrained("geolocal/StreetCLIP")
7
+ processor = CLIPProcessor.from_pretrained("geolocal/StreetCLIP")
8
+
9
+ labels = ['Albania', 'Andorra', 'Argentina', 'Australia', 'Austria', 'Bangladesh', 'Belgium', 'Bermuda', 'Bhutan', 'Bolivia', 'Botswana', 'Brazil', 'Bulgaria', 'Cambodia', 'Canada', 'Chile', 'China', 'Colombia', 'Croatia', 'Czech Republic', 'Denmark', 'Dominican Republic', 'Ecuador', 'Estonia', 'Finland', 'France', 'Germany', 'Ghana', 'Greece', 'Greenland', 'Guam', 'Guatemala', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Ireland', 'Israel', 'Italy', 'Japan', 'Jordan', 'Kenya', 'Kyrgyzstan', 'Laos', 'Latvia', 'Lesotho', 'Lithuania', 'Luxembourg', 'Macedonia', 'Madagascar', 'Malaysia', 'Malta', 'Mexico', 'Monaco', 'Mongolia', 'Montenegro', 'Netherlands', 'New Zealand', 'Nigeria', 'Norway', 'Pakistan', 'Palestine', 'Peru', 'Philippines', 'Poland', 'Portugal', 'Puerto Rico', 'Romania', 'Russia', 'Rwanda', 'Senegal', 'Serbia', 'Singapore', 'Slovakia', 'Slovenia', 'South Africa', 'South Korea', 'Spain', 'Sri Lanka', 'Swaziland', 'Sweden', 'Switzerland', 'Taiwan', 'Thailand', 'Tunisia', 'Turkey', 'Uganda', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'United States', 'Uruguay']
10
+
11
+
12
+ def classify(image):
13
+ inputs = processor(text=labels, images=image, return_tensors="pt", padding=True)
14
+ with torch.no_grad():
15
+ outputs = model(**inputs)
16
+ logits_per_image = outputs.logits_per_image
17
+ prediction = logits_per_image.softmax(dim=1)
18
+ confidences = {labels[i]: float(prediction[0][i].item()) for i in range(len(labels))}
19
+ return confidences
20
+
21
+ DESCRIPTION = """
22
+ <img src='file/logo.jpg' alt='logo' style='width:100px;float:left'/><h1 style='padding-top:30px'>&nbsp;StreetClip Model used for classification - 92 countries supported</h1>
23
+ <h2 style='margin-top:50px'> This Space demonstrates how the StreetClip model (https://huggingface.co/geolocal/StreetCLIP) can be used to geolocate images (classification per country).</h2>
24
+ <p>
25
+ 🌎 <b>List of countries supported</b>: Albania, Andorra, Argentina, Australia, Austria, Bangladesh, Belgium, Bermuda, Bhutan, Bolivia, Botswana, Brazil, Bulgaria, Cambodia, Canada, Chile, China, Colombia, Croatia, Czech Republic, Denmark, Dominican Republic, Ecuador, Estonia, Finland, France, Germany, Ghana, Greece, Greenland, Guam, Guatemala, Hungary, Iceland, India, Indonesia, Ireland, Israel, Italy, Japan, Jordan, Kenya, Kyrgyzstan, Laos, Latvia, Lesotho, Lithuania, Luxembourg, Macedonia, Madagascar, Malaysia, Malta, Mexico, Monaco, Mongolia, Montenegro, Netherlands, New Zealand, Nigeria, Norway, Pakistan, Palestine, Peru, Philippines, Poland, Portugal, Puerto Rico, Romania, Russia, Rwanda, Senegal, Serbia, Singapore, Slovakia, Slovenia, South Africa, South Korea, Spain, Sri Lanka, Swaziland, Sweden, Switzerland, Taiwan, Thailand, Tunisia, Turkey, Uganda, Ukraine, United Arab Emirates, United Kingdom, United States, Uruguay
26
+ </p>
27
+ ---<br>
28
+ As a derivate work of [StreetClip] (https://huggingface.co/geolocal/StreetCLIP),this demo is governed by the original Create Commons Attribution Non Commercial 4.0.
29
+ """
30
+
31
+ image = gr.Image(label="Input image")
32
+ label = gr.Label(num_top_classes=10,label="Top 10 countries")
33
+
34
+ demo = gr.Interface(
35
+ fn=classify,
36
+ inputs=image,
37
+ outputs=label,
38
+ interpretation="default",
39
+ title="StreetClip Classification",
40
+ description=DESCRIPTION,
41
+ article="Interpretation requires time to process, please be patient πŸ™πŸ»",
42
+ examples=["turkey.png","croatia.jpg"],
43
+ allow_flagging="never",
44
+ )
45
+
46
+ demo.launch(favicon_path='favicon.ico')
croatia.jpg ADDED
favicon.ico ADDED
logo.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ Pillow
4
+ gradio
turkey.jpg ADDED