hindi-characters / README.md
ygyash's picture
Update README.md
c15e9d4 verified

A newer version of the Streamlit SDK is available: 1.51.0

Upgrade
metadata
title: Hindi Character Classifier
emoji: 🖼️
colorFrom: red
colorTo: blue
sdk: streamlit
sdk_version: 1.25.0
library_name: torch
pipeline_tag: image-classification

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. Ensure you have the following files in your space:
    • your_model_file.py: Contains the HindiCharacterCNN class definition.
    • your_model.safetensors: The model's weights.
    • app.py: The Streamlit application script.
    • requirements.txt: Lists your dependencies (torch, torchvision, pillow, streamlit).
  2. Example app.py (Streamlit):
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)}")