1from huggingface_hub import hf_hub_download
2from tensorflow.keras.models import load_model
3from tensorflow.keras.preprocessing import image
4import numpy as np
5
6# 1. Hugging Face repo ID and model filename
7repo_id = "your-username/your-repo" # Replace with your repo ID
8filename = "hieroglyphics_modelMobileNetV2.keras" # Replace with your model filename
9
10# 2. Download the model from Hugging Face Hub
11model_path = hf_hub_download(repo_id=repo_id, filename=filename)
12model = load_model(model_path)
13
14# 3. Class names corresponding to model output indices
15class_names = [
16 "100", "Her", "Woman", "among", "angry", "ankh", "aroura", "at", "bad", "bandage",
17 "bee", "belongs", "birth", "board", "book", "boy", "branch", "bread", "brewer", "builder",
18 "bury", "canal", "cloth", "cobra", "composite_bow", "cooked", "corpse", "dessert", "divide",
19 "duck", "elephant", "enclosed", "eye", "fabric", "face", "falcon", "fingre", "fish", "flail",
20 "folded", "foot", "galena", "giraffe", "he", "hit", "horn", "king", "leg", "length", "life",
21 "limits", "lion", "lizard", "loaf", "man", "mascot", "meet", "mother", "mouth", "musical",
22 "nile", "not", "now", "nurse", "nursing", "occur", "one", "owl", "pair", "papyrus", "pool",
23 "quailchick", "reed", "ring", "rope", "ruler", "sail", "sandal", "semen", "small", "snake",
24 "soldier", "star", "stick", "swallow", "this", "to", "turtle", "viper", "wall", "water", "you"
25]
26
27# 4. Function to prepare input image for prediction
28def prepare_image(img_path, target_size=(224, 224)):
29 img = image.load_img(img_path, target_size=target_size) # Load and resize image
30 img_array = image.img_to_array(img) # Convert to array
31 img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
32 img_array = img_array / 255.0 # Normalize
33 return img_array
34
35# 5. Provide the path to your test image here
36img_path = "path/to/your/hieroglyph_image.jpg"
37img = prepare_image(img_path)
38
39# 6. Run prediction
40predictions = model.predict(img)
41predicted_index = np.argmax(predictions)
42predicted_label = class_names[predicted_index]
43
44print(f"Predicted Hieroglyph: {predicted_label}")