CoolFace
Apppublic

ygyash/hindi-characters-endpoint

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
App README

Hindi Character CNN

This model is a Convolutional Neural Network (CNN) for Hindi character image classification, built with PyTorch.

Usage

This model is designed to classify images of Hindi characters. It takes a 32x32 pixel RGB image as input and outputs the predicted Hindi character class.

To use this model within a Hugging Face Space (Streamlit example):

  1. 1.Ensure you have the following files in your space:
  2. 2.your_model_file.py: Contains the HindiCharacterCNN class definition.
  3. 3.your_model.safetensors: The model's weights.
  4. 4.app.py: The Streamlit application script.
  5. 5.requirements.txt: Lists your dependencies (torch, torchvision, pillow, streamlit).
  6. 6.Example `app.py` (Streamlit):
python
import streamlit as st
import torch
from PIL import Image
import torchvision.transforms as transforms
from your_model_file import HindiCharacterCNN  # Replace with your model file

# Load model
model = HindiCharacterCNN(num_labels=36)
model.load_state_dict(torch.load("your_model.safetensors", map_location=torch.device('cpu')))
model.eval()

# Preprocessing
transform = transforms.Compose([
    transforms.Resize((32, 32)),
    transforms.ToTensor(),
])

st.title("Hindi Character Classification")

uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])

if uploaded_file is not None:
    image = Image.open(uploaded_file).convert('RGB')
    st.image(image, caption="Uploaded Image.", use_column_width=True)
    st.write("")
    st.write("Classifying...")

    image = transform(image).unsqueeze(0)

    with torch.no_grad():
        output = model(image)
        probabilities = torch.nn.functional.softmax(output[0], dim=0)
        _, predicted_class = torch.max(probabilities, 0)
        st.write(f"Predicted Class: {int(predicted_class)}")