File size: 2,004 Bytes
b17df61
c15e9d4
 
 
 
 
 
2399f17
 
b17df61
 
2399f17
 
 
 
 
 
c15e9d4
2399f17
c15e9d4
 
 
 
 
 
 
 
2399f17
 
c15e9d4
2399f17
c15e9d4
 
 
2399f17
c15e9d4
2399f17
c15e9d4
2399f17
 
c15e9d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
---
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):**

```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)}")