Spaces:
Sleeping
Sleeping
Update app.py
#3
by opinder2906 - opened
app.py
CHANGED
|
@@ -17,32 +17,29 @@ class_names = {
|
|
| 17 |
|
| 18 |
# Fixed image URLs with working links
|
| 19 |
# Updated reliable image URLs
|
|
|
|
| 20 |
image_urls = {
|
| 21 |
"Lion": "https://upload.wikimedia.org/wikipedia/commons/7/73/Lion_waiting_in_Namibia.jpg",
|
| 22 |
-
"Donkey": "https://upload.wikimedia.org/wikipedia/commons/8/
|
| 23 |
"Cow": "https://upload.wikimedia.org/wikipedia/commons/0/0c/Cow_female_black_white.jpg",
|
| 24 |
-
"Cat": "https://upload.wikimedia.org/wikipedia/commons/
|
| 25 |
-
"Dog": "https://upload.wikimedia.org/wikipedia/commons/d/
|
| 26 |
-
"Sheep": "https://upload.wikimedia.org/wikipedia/commons/
|
| 27 |
-
"Frog": "https://upload.wikimedia.org/wikipedia/commons/
|
| 28 |
-
"Bird": "https://upload.wikimedia.org/wikipedia/commons/f/
|
| 29 |
-
"Monkey": "https://upload.wikimedia.org/wikipedia/commons/
|
| 30 |
-
"Chicken": "https://upload.wikimedia.org/wikipedia/commons/
|
| 31 |
}
|
| 32 |
|
| 33 |
def download_image(url):
|
| 34 |
"""Download image with fallback to placeholder"""
|
| 35 |
-
if not url:
|
| 36 |
-
return Image.new('RGB', (300, 200), color='gray')
|
| 37 |
try:
|
| 38 |
response = requests.get(url, timeout=10)
|
| 39 |
response.raise_for_status()
|
| 40 |
return Image.open(BytesIO(response.content)).convert("RGB")
|
| 41 |
except Exception:
|
| 42 |
-
# Return placeholder if download fails
|
| 43 |
return Image.new('RGB', (300, 200), color='gray')
|
| 44 |
|
| 45 |
-
|
| 46 |
def preprocess(audio_path):
|
| 47 |
"""Audio preprocessing with error handling"""
|
| 48 |
try:
|
|
|
|
| 17 |
|
| 18 |
# Fixed image URLs with working links
|
| 19 |
# Updated reliable image URLs
|
| 20 |
+
# Fully working image URLs
|
| 21 |
image_urls = {
|
| 22 |
"Lion": "https://upload.wikimedia.org/wikipedia/commons/7/73/Lion_waiting_in_Namibia.jpg",
|
| 23 |
+
"Donkey": "https://upload.wikimedia.org/wikipedia/commons/8/85/%C3%82ne_d%27Ethiopie.jpg",
|
| 24 |
"Cow": "https://upload.wikimedia.org/wikipedia/commons/0/0c/Cow_female_black_white.jpg",
|
| 25 |
+
"Cat": "https://upload.wikimedia.org/wikipedia/commons/6/6e/Black_and_white_cat_on_rug.jpg",
|
| 26 |
+
"Dog": "https://upload.wikimedia.org/wikipedia/commons/d/db/Heterochromia_dog%2C_Struga.jpg",
|
| 27 |
+
"Sheep": "https://upload.wikimedia.org/wikipedia/commons/2/2c/Flock_of_sheep.jpg",
|
| 28 |
+
"Frog": "https://upload.wikimedia.org/wikipedia/commons/c/cb/The_Green_and_Golden_Bell_Frog.jpg",
|
| 29 |
+
"Bird": "https://upload.wikimedia.org/wikipedia/commons/f/fb/Brown_thrasher_in_CP_%2802147%29.jpg",
|
| 30 |
+
"Monkey": "https://upload.wikimedia.org/wikipedia/commons/c/c8/Monkey_eating.jpg",
|
| 31 |
+
"Chicken": "https://upload.wikimedia.org/wikipedia/commons/b/b2/Gallus_gallus_domesticus_487567856.jpg"
|
| 32 |
}
|
| 33 |
|
| 34 |
def download_image(url):
|
| 35 |
"""Download image with fallback to placeholder"""
|
|
|
|
|
|
|
| 36 |
try:
|
| 37 |
response = requests.get(url, timeout=10)
|
| 38 |
response.raise_for_status()
|
| 39 |
return Image.open(BytesIO(response.content)).convert("RGB")
|
| 40 |
except Exception:
|
|
|
|
| 41 |
return Image.new('RGB', (300, 200), color='gray')
|
| 42 |
|
|
|
|
| 43 |
def preprocess(audio_path):
|
| 44 |
"""Audio preprocessing with error handling"""
|
| 45 |
try:
|