Spaces:
Running
Running
adds lotties
Browse files- core/seed.py +70 -53
- static/paw-map-clean/como-resgatar-um-cachorro-de-rua.jpg +0 -0
- static/paw-map-clean/images (1).jpg +0 -0
- static/paw-map-clean/images (2).jpg +0 -0
- static/paw-map-clean/images.jpg +0 -0
- static/paw-map-clean/meu-primeiro-cachorro-pet.jpg +0 -0
- static/paw-map-clean/o-que-fazer-se-encontrar-um-cachorro-na-rua-1024x768.webp +0 -0
core/seed.py
CHANGED
|
@@ -10,114 +10,128 @@ import numpy as np
|
|
| 10 |
|
| 11 |
log = logging.getLogger(__name__)
|
| 12 |
|
| 13 |
-
# Animais de demonstração
|
|
|
|
|
|
|
| 14 |
_SEED_ANIMALS = [
|
| 15 |
{
|
| 16 |
"species": "dog",
|
|
|
|
|
|
|
| 17 |
"description": {
|
| 18 |
"species": "dog",
|
| 19 |
"breed_estimate": "SRD",
|
| 20 |
"size": "médio",
|
| 21 |
-
"primary_color": "
|
| 22 |
-
"secondary_colors": ["
|
| 23 |
-
"distinctive_marks": ["
|
| 24 |
"condition": "saudável",
|
| 25 |
-
"description_text": "medium caramel
|
| 26 |
"_ai_success": True,
|
| 27 |
},
|
| 28 |
"sightings": [
|
| 29 |
-
{"lat": -15.7560, "lng": -47.8920, "days_ago":
|
| 30 |
-
{"lat": -15.
|
| 31 |
-
{"lat": -15.7575, "lng": -47.8948, "days_ago": 2, "notes": "Aparenta saudável"},
|
| 32 |
],
|
| 33 |
},
|
| 34 |
{
|
| 35 |
-
"species": "
|
|
|
|
|
|
|
| 36 |
"description": {
|
| 37 |
-
"species": "
|
| 38 |
"breed_estimate": "SRD",
|
| 39 |
-
"size": "
|
| 40 |
-
"primary_color": "
|
| 41 |
-
"secondary_colors": [],
|
| 42 |
-
"distinctive_marks": [],
|
| 43 |
"condition": "saudável",
|
| 44 |
-
"description_text": "
|
| 45 |
"_ai_success": True,
|
| 46 |
},
|
| 47 |
"sightings": [
|
| 48 |
-
{"lat": -15.
|
|
|
|
|
|
|
| 49 |
],
|
| 50 |
},
|
| 51 |
{
|
| 52 |
"species": "dog",
|
|
|
|
|
|
|
| 53 |
"description": {
|
| 54 |
"species": "dog",
|
| 55 |
"breed_estimate": "SRD",
|
| 56 |
"size": "grande",
|
| 57 |
-
"primary_color": "
|
| 58 |
-
"secondary_colors": [
|
| 59 |
-
"distinctive_marks": ["
|
| 60 |
-
"condition": "
|
| 61 |
-
"description_text": "large
|
| 62 |
"_ai_success": True,
|
| 63 |
},
|
| 64 |
"sightings": [
|
| 65 |
-
{"lat": -15.
|
| 66 |
-
{"lat": -15.
|
| 67 |
],
|
| 68 |
},
|
| 69 |
{
|
| 70 |
-
"species": "
|
|
|
|
|
|
|
| 71 |
"description": {
|
| 72 |
-
"species": "
|
| 73 |
"breed_estimate": "SRD",
|
| 74 |
"size": "médio",
|
| 75 |
-
"primary_color": "
|
| 76 |
-
"secondary_colors": ["
|
| 77 |
-
"distinctive_marks": ["
|
| 78 |
"condition": "saudável",
|
| 79 |
-
"description_text": "medium
|
| 80 |
"_ai_success": True,
|
| 81 |
},
|
| 82 |
"sightings": [
|
| 83 |
-
{"lat": -15.
|
| 84 |
-
{"lat": -15.
|
| 85 |
],
|
| 86 |
},
|
| 87 |
{
|
| 88 |
-
"species": "
|
|
|
|
|
|
|
| 89 |
"description": {
|
| 90 |
-
"species": "
|
| 91 |
-
"breed_estimate": "
|
| 92 |
-
"size": "
|
| 93 |
-
"primary_color": "
|
| 94 |
"secondary_colors": [],
|
| 95 |
-
"distinctive_marks": ["
|
| 96 |
"condition": "saudável",
|
| 97 |
-
"description_text": "
|
| 98 |
"_ai_success": True,
|
| 99 |
},
|
| 100 |
"sightings": [
|
| 101 |
-
{"lat": -15.
|
| 102 |
],
|
| 103 |
},
|
| 104 |
{
|
| 105 |
-
"species": "
|
|
|
|
|
|
|
| 106 |
"description": {
|
| 107 |
-
"species": "
|
| 108 |
"breed_estimate": "SRD",
|
| 109 |
-
"size": "
|
| 110 |
-
"primary_color": "
|
| 111 |
"secondary_colors": [],
|
| 112 |
-
"distinctive_marks": ["
|
| 113 |
"condition": "saudável",
|
| 114 |
-
"description_text": "
|
| 115 |
"_ai_success": True,
|
| 116 |
},
|
| 117 |
"sightings": [
|
| 118 |
-
{"lat": -15.
|
| 119 |
-
{"lat": -15.
|
| 120 |
-
{"lat": -15.7695, "lng": -47.8848, "days_ago": 1, "notes": "Parece bem alimentado"},
|
| 121 |
],
|
| 122 |
},
|
| 123 |
]
|
|
@@ -145,17 +159,18 @@ def seed_if_empty(db) -> None:
|
|
| 145 |
for animal_data in _SEED_ANIMALS:
|
| 146 |
sightings = animal_data["sightings"]
|
| 147 |
desc = animal_data["description"]
|
|
|
|
| 148 |
|
| 149 |
-
# last_seen = data do avistamento mais recente
|
| 150 |
most_recent_days = min(s["days_ago"] for s in sightings)
|
| 151 |
last_seen = now - timedelta(days=most_recent_days)
|
| 152 |
first_seen = now - timedelta(days=max(s["days_ago"] for s in sightings))
|
| 153 |
|
| 154 |
cur = conn.execute(
|
| 155 |
-
"INSERT INTO animals (species, description, embedding, first_seen, last_seen, sighting_count)"
|
| 156 |
-
" VALUES (?, ?, ?, ?, ?, ?)",
|
| 157 |
(
|
| 158 |
animal_data["species"],
|
|
|
|
| 159 |
json.dumps(desc, ensure_ascii=False),
|
| 160 |
_random_embedding(),
|
| 161 |
first_seen.strftime("%Y-%m-%d %H:%M:%S"),
|
|
@@ -165,14 +180,16 @@ def seed_if_empty(db) -> None:
|
|
| 165 |
)
|
| 166 |
animal_id = cur.lastrowid
|
| 167 |
|
| 168 |
-
for s in sightings:
|
| 169 |
created_at = now - timedelta(days=s["days_ago"])
|
|
|
|
|
|
|
| 170 |
conn.execute(
|
| 171 |
"INSERT INTO sightings (animal_id, photo_path, latitude, longitude, notes, created_at)"
|
| 172 |
" VALUES (?, ?, ?, ?, ?, ?)",
|
| 173 |
(
|
| 174 |
animal_id,
|
| 175 |
-
|
| 176 |
s["lat"],
|
| 177 |
s["lng"],
|
| 178 |
s.get("notes", ""),
|
|
|
|
| 10 |
|
| 11 |
log = logging.getLogger(__name__)
|
| 12 |
|
| 13 |
+
# Animais de demonstração espalhados por Brasília, DF.
|
| 14 |
+
# photo_path é relativo ao DATA_DIR (ex: 'photos/seed/pretao.jpg'),
|
| 15 |
+
# servido em /photos/seed/pretao.jpg pelo static mount.
|
| 16 |
_SEED_ANIMALS = [
|
| 17 |
{
|
| 18 |
"species": "dog",
|
| 19 |
+
"name": "Pretão",
|
| 20 |
+
"photo_filename": "pretao.jpg",
|
| 21 |
"description": {
|
| 22 |
"species": "dog",
|
| 23 |
"breed_estimate": "SRD",
|
| 24 |
"size": "médio",
|
| 25 |
+
"primary_color": "preto",
|
| 26 |
+
"secondary_colors": ["caramelo"],
|
| 27 |
+
"distinctive_marks": ["focinho caramelo", "patas caramelo"],
|
| 28 |
"condition": "saudável",
|
| 29 |
+
"description_text": "medium black dog with caramel markings on face and paws, calm and friendly",
|
| 30 |
"_ai_success": True,
|
| 31 |
},
|
| 32 |
"sightings": [
|
| 33 |
+
{"lat": -15.7560, "lng": -47.8920, "days_ago": 10, "notes": "Deitado na calçada da 406 Norte, aceitou carinho"},
|
| 34 |
+
{"lat": -15.7555, "lng": -47.8912, "days_ago": 3, "notes": "Voltou pro mesmo ponto, parece ter território fixo"},
|
|
|
|
| 35 |
],
|
| 36 |
},
|
| 37 |
{
|
| 38 |
+
"species": "dog",
|
| 39 |
+
"name": "Mel",
|
| 40 |
+
"photo_filename": "mel.webp",
|
| 41 |
"description": {
|
| 42 |
+
"species": "dog",
|
| 43 |
"breed_estimate": "SRD",
|
| 44 |
+
"size": "médio",
|
| 45 |
+
"primary_color": "branco",
|
| 46 |
+
"secondary_colors": ["caramelo"],
|
| 47 |
+
"distinctive_marks": ["manchas caramelo nas costas", "orelhas caramelo"],
|
| 48 |
"condition": "saudável",
|
| 49 |
+
"description_text": "medium white dog with caramel patches, resting on wooden surface near closed shop",
|
| 50 |
"_ai_success": True,
|
| 51 |
},
|
| 52 |
"sightings": [
|
| 53 |
+
{"lat": -15.8450, "lng": -47.8700, "days_ago": 20, "notes": "Próximo à feira do Lago Sul, dócil"},
|
| 54 |
+
{"lat": -15.8442, "lng": -47.8692, "days_ago": 8, "notes": "Mesma área, aparenta bem alimentada"},
|
| 55 |
+
{"lat": -15.8438, "lng": -47.8705, "days_ago": 1, "notes": "Vista descansando na entrada de um comércio"},
|
| 56 |
],
|
| 57 |
},
|
| 58 |
{
|
| 59 |
"species": "dog",
|
| 60 |
+
"name": "Caramelo",
|
| 61 |
+
"photo_filename": "caramelo.jpg",
|
| 62 |
"description": {
|
| 63 |
"species": "dog",
|
| 64 |
"breed_estimate": "SRD",
|
| 65 |
"size": "grande",
|
| 66 |
+
"primary_color": "caramelo",
|
| 67 |
+
"secondary_colors": [],
|
| 68 |
+
"distinctive_marks": ["pelagem densa", "cauda enrolada"],
|
| 69 |
+
"condition": "saudável",
|
| 70 |
+
"description_text": "large golden caramel mixed breed dog, standing alert near road in Taguatinga",
|
| 71 |
"_ai_success": True,
|
| 72 |
},
|
| 73 |
"sightings": [
|
| 74 |
+
{"lat": -15.8300, "lng": -47.9900, "days_ago": 45, "notes": "Visto na marginal de Taguatinga, sozinho"},
|
| 75 |
+
{"lat": -15.8312, "lng": -47.9888, "days_ago": 15, "notes": "Ainda na área, precisa de atenção"},
|
| 76 |
],
|
| 77 |
},
|
| 78 |
{
|
| 79 |
+
"species": "dog",
|
| 80 |
+
"name": "Manchinha",
|
| 81 |
+
"photo_filename": "manchinha.jpg",
|
| 82 |
"description": {
|
| 83 |
+
"species": "dog",
|
| 84 |
"breed_estimate": "SRD",
|
| 85 |
"size": "médio",
|
| 86 |
+
"primary_color": "branco",
|
| 87 |
+
"secondary_colors": ["preto"],
|
| 88 |
+
"distinctive_marks": ["manchas pretas na cabeça", "focinho malhado", "coleira verde"],
|
| 89 |
"condition": "saudável",
|
| 90 |
+
"description_text": "medium white dog with black patches on head, spotted muzzle, wearing green collar, very friendly",
|
| 91 |
"_ai_success": True,
|
| 92 |
},
|
| 93 |
"sightings": [
|
| 94 |
+
{"lat": -15.8010, "lng": -47.8960, "days_ago": 5, "notes": "Super dócil, tem coleira mas sem identificação — 308 Sul"},
|
| 95 |
+
{"lat": -15.8005, "lng": -47.8950, "days_ago": 1, "notes": "Brincando com passantes perto do comércio"},
|
| 96 |
],
|
| 97 |
},
|
| 98 |
{
|
| 99 |
+
"species": "cat",
|
| 100 |
+
"name": "Cinzinha",
|
| 101 |
+
"photo_filename": "cinzinha.jpg",
|
| 102 |
"description": {
|
| 103 |
+
"species": "cat",
|
| 104 |
+
"breed_estimate": "SRD",
|
| 105 |
+
"size": "pequeno",
|
| 106 |
+
"primary_color": "cinza",
|
| 107 |
"secondary_colors": [],
|
| 108 |
+
"distinctive_marks": ["listras tigradas", "olhos amarelos grandes"],
|
| 109 |
"condition": "saudável",
|
| 110 |
+
"description_text": "small grey tabby kitten with large yellow eyes, timid but curious",
|
| 111 |
"_ai_success": True,
|
| 112 |
},
|
| 113 |
"sightings": [
|
| 114 |
+
{"lat": -15.7620, "lng": -47.8875, "days_ago": 2, "notes": "Filhote na W3 Norte, aceita comida com cuidado"},
|
| 115 |
],
|
| 116 |
},
|
| 117 |
{
|
| 118 |
+
"species": "cat",
|
| 119 |
+
"name": "Laranja",
|
| 120 |
+
"photo_filename": "laranja.jpg",
|
| 121 |
"description": {
|
| 122 |
+
"species": "cat",
|
| 123 |
"breed_estimate": "SRD",
|
| 124 |
+
"size": "médio",
|
| 125 |
+
"primary_color": "laranja",
|
| 126 |
"secondary_colors": [],
|
| 127 |
+
"distinctive_marks": ["pelagem totalmente ruiva", "parte de colônia"],
|
| 128 |
"condition": "saudável",
|
| 129 |
+
"description_text": "medium orange tabby cat, part of a feral colony near dumpsters in Ceilândia",
|
| 130 |
"_ai_success": True,
|
| 131 |
},
|
| 132 |
"sightings": [
|
| 133 |
+
{"lat": -15.8170, "lng": -48.1080, "days_ago": 7, "notes": "Colônia de gatos ruivos perto da feira de Ceilândia"},
|
| 134 |
+
{"lat": -15.8165, "lng": -48.1072, "days_ago": 0, "notes": "Dois gatos laranja, parecem saudáveis"},
|
|
|
|
| 135 |
],
|
| 136 |
},
|
| 137 |
]
|
|
|
|
| 159 |
for animal_data in _SEED_ANIMALS:
|
| 160 |
sightings = animal_data["sightings"]
|
| 161 |
desc = animal_data["description"]
|
| 162 |
+
photo_path = f"photos/seed/{animal_data['photo_filename']}"
|
| 163 |
|
|
|
|
| 164 |
most_recent_days = min(s["days_ago"] for s in sightings)
|
| 165 |
last_seen = now - timedelta(days=most_recent_days)
|
| 166 |
first_seen = now - timedelta(days=max(s["days_ago"] for s in sightings))
|
| 167 |
|
| 168 |
cur = conn.execute(
|
| 169 |
+
"INSERT INTO animals (species, name, description, embedding, first_seen, last_seen, sighting_count)"
|
| 170 |
+
" VALUES (?, ?, ?, ?, ?, ?, ?)",
|
| 171 |
(
|
| 172 |
animal_data["species"],
|
| 173 |
+
animal_data.get("name"),
|
| 174 |
json.dumps(desc, ensure_ascii=False),
|
| 175 |
_random_embedding(),
|
| 176 |
first_seen.strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
| 180 |
)
|
| 181 |
animal_id = cur.lastrowid
|
| 182 |
|
| 183 |
+
for i, s in enumerate(sightings):
|
| 184 |
created_at = now - timedelta(days=s["days_ago"])
|
| 185 |
+
# foto só no avistamento mais recente
|
| 186 |
+
s_photo = photo_path if i == len(sightings) - 1 else None
|
| 187 |
conn.execute(
|
| 188 |
"INSERT INTO sightings (animal_id, photo_path, latitude, longitude, notes, created_at)"
|
| 189 |
" VALUES (?, ?, ?, ?, ?, ?)",
|
| 190 |
(
|
| 191 |
animal_id,
|
| 192 |
+
s_photo,
|
| 193 |
s["lat"],
|
| 194 |
s["lng"],
|
| 195 |
s.get("notes", ""),
|
static/paw-map-clean/como-resgatar-um-cachorro-de-rua.jpg
ADDED
|
static/paw-map-clean/images (1).jpg
ADDED
|
static/paw-map-clean/images (2).jpg
ADDED
|
static/paw-map-clean/images.jpg
ADDED
|
static/paw-map-clean/meu-primeiro-cachorro-pet.jpg
ADDED
|
static/paw-map-clean/o-que-fazer-se-encontrar-um-cachorro-na-rua-1024x768.webp
ADDED
|