krishnamishra8848 commited on
Commit
7e8a9f8
·
verified ·
1 Parent(s): 8fb71b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -8
app.py CHANGED
@@ -1,12 +1,11 @@
1
  import streamlit as st
2
  import numpy as np
3
- import cv2
4
  from tensorflow.keras.models import load_model
5
  from PIL import Image
6
  import requests
7
 
8
  # Load the model from Hugging Face
9
- @st.cache(allow_output_mutation=True)
10
  def load_model_from_hf():
11
  url = "https://huggingface.co/krishnamishra8848/Devanagari_Character_Recognition/resolve/main/saved_model.keras"
12
  response = requests.get(url)
@@ -17,7 +16,7 @@ def load_model_from_hf():
17
 
18
  model = load_model_from_hf()
19
 
20
- # Label mapping
21
  label_mapping = [
22
  "क", "ख", "ग", "घ", "ङ", "च", "छ", "ज", "झ", "ञ",
23
  "ट", "ठ", "ड", "ढ", "ण", "त", "थ", "द", "ध", "न",
@@ -35,15 +34,11 @@ uploaded_file = st.file_uploader("Choose a file", type=["jpg", "png", "jpeg"])
35
 
36
  if uploaded_file is not None:
37
  # Load and preprocess the image
38
- img = Image.open(uploaded_file)
39
- img = img.convert("L") # Convert to grayscale
40
  img_resized = img.resize((32, 32)) # Resize to 32x32
41
  img_array = np.array(img_resized).astype("float32") / 255.0 # Normalize
42
  img_input = img_array.reshape(1, 32, 32, 1) # Reshape for the model
43
 
44
- # Display uploaded image
45
- st.image(img, caption="Uploaded Image", use_column_width=True)
46
-
47
  # Make prediction
48
  prediction = model.predict(img_input)
49
  predicted_class_index = np.argmax(prediction)
 
1
  import streamlit as st
2
  import numpy as np
 
3
  from tensorflow.keras.models import load_model
4
  from PIL import Image
5
  import requests
6
 
7
  # Load the model from Hugging Face
8
+ @st.cache_resource
9
  def load_model_from_hf():
10
  url = "https://huggingface.co/krishnamishra8848/Devanagari_Character_Recognition/resolve/main/saved_model.keras"
11
  response = requests.get(url)
 
16
 
17
  model = load_model_from_hf()
18
 
19
+ # Nepali characters mapping
20
  label_mapping = [
21
  "क", "ख", "ग", "घ", "ङ", "च", "छ", "ज", "झ", "ञ",
22
  "ट", "ठ", "ड", "ढ", "ण", "त", "थ", "द", "ध", "न",
 
34
 
35
  if uploaded_file is not None:
36
  # Load and preprocess the image
37
+ img = Image.open(uploaded_file).convert("L") # Convert to grayscale
 
38
  img_resized = img.resize((32, 32)) # Resize to 32x32
39
  img_array = np.array(img_resized).astype("float32") / 255.0 # Normalize
40
  img_input = img_array.reshape(1, 32, 32, 1) # Reshape for the model
41
 
 
 
 
42
  # Make prediction
43
  prediction = model.predict(img_input)
44
  predicted_class_index = np.argmax(prediction)