krishnamishra8848 commited on
Commit
fde3f5a
·
verified ·
1 Parent(s): 1d55706

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +59 -1
README.md CHANGED
@@ -1,4 +1,62 @@
1
  ---
2
  license: apache-2.0
3
  pipeline_tag: image-classification
4
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
  pipeline_tag: image-classification
4
+ ---
5
+ # Devanagari Character Recognition
6
+
7
+ ```python
8
+ # Example Code: You can test our model in Google Colab or Any where you want
9
+ import requests
10
+ from tensorflow.keras.models import load_model
11
+
12
+ # Download the model from Hugging Face
13
+ url = "https://huggingface.co/krishnamishra8848/Devanagari_Character_Recognition/resolve/main/saved_model.keras"
14
+ model_path = "saved_model.keras"
15
+
16
+ response = requests.get(url)
17
+ with open(model_path, "wb") as f:
18
+ f.write(response.content)
19
+
20
+ # Load the model
21
+ model = load_model(model_path)
22
+
23
+ # Nepali characters mapping
24
+ label_mapping = [
25
+ "क", "ख", "ग", "घ", "ङ", "च", "छ", "ज", "झ", "ञ",
26
+ "ट", "ठ", "ड", "ढ", "ण", "त", "थ", "द", "ध", "न",
27
+ "प", "फ", "ब", "भ", "म", "य", "र", "ल", "व", "श",
28
+ "ष", "स", "ह", "क्ष", "त्र", "ज्ञ", "०", "१", "२", "३",
29
+ "४", "५", "६", "७", "८", "९"
30
+ ]
31
+
32
+ # File upload
33
+ uploaded = files.upload()
34
+
35
+ # Process the uploaded image
36
+ for filename in uploaded.keys():
37
+ # Load the image
38
+ img = Image.open(filename)
39
+
40
+ # Convert the image to grayscale if necessary
41
+ img = np.array(img)
42
+ if len(img.shape) == 3: # If the image is RGB
43
+ img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
44
+
45
+ # Resize to 32x32
46
+ img_resized = cv2.resize(img, (32, 32))
47
+
48
+ # Normalize the pixel values
49
+ img_normalized = img_resized.astype("float32") / 255.0
50
+
51
+ # Reshape to match the model's input shape
52
+ img_input = img_normalized.reshape(1, 32, 32, 1)
53
+
54
+ # Make a prediction
55
+ prediction = model.predict(img_input)
56
+ predicted_class_index = np.argmax(prediction)
57
+
58
+ # Get the predicted Nepali character
59
+ predicted_character = label_mapping[predicted_class_index]
60
+ print(f"Predicted Character: {predicted_character}")
61
+
62
+