Spaces:
Sleeping
Sleeping
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,4 +1,10 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
library_name: torch
|
| 3 |
pipeline_tag: image-classification
|
| 4 |
---
|
|
@@ -9,16 +15,49 @@ This model is a Convolutional Neural Network (CNN) for Hindi character image cla
|
|
| 9 |
|
| 10 |
## Usage
|
| 11 |
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
```python
|
|
|
|
| 17 |
import torch
|
| 18 |
-
from
|
|
|
|
|
|
|
| 19 |
|
|
|
|
| 20 |
model = HindiCharacterCNN(num_labels=36)
|
| 21 |
-
model.load_state_dict(torch.load("your_model.safetensors"))
|
| 22 |
model.eval()
|
| 23 |
|
| 24 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Hindi Character Classifier
|
| 3 |
+
emoji: 🖼️
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
sdk_version: "1.25.0"
|
| 8 |
library_name: torch
|
| 9 |
pipeline_tag: image-classification
|
| 10 |
---
|
|
|
|
| 15 |
|
| 16 |
## Usage
|
| 17 |
|
| 18 |
+
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.
|
| 19 |
|
| 20 |
+
**To use this model within a Hugging Face Space (Streamlit example):**
|
| 21 |
+
|
| 22 |
+
1. **Ensure you have the following files in your space:**
|
| 23 |
+
* `your_model_file.py`: Contains the `HindiCharacterCNN` class definition.
|
| 24 |
+
* `your_model.safetensors`: The model's weights.
|
| 25 |
+
* `app.py`: The Streamlit application script.
|
| 26 |
+
* `requirements.txt`: Lists your dependencies (torch, torchvision, pillow, streamlit).
|
| 27 |
+
2. **Example `app.py` (Streamlit):**
|
| 28 |
|
| 29 |
```python
|
| 30 |
+
import streamlit as st
|
| 31 |
import torch
|
| 32 |
+
from PIL import Image
|
| 33 |
+
import torchvision.transforms as transforms
|
| 34 |
+
from your_model_file import HindiCharacterCNN # Replace with your model file
|
| 35 |
|
| 36 |
+
# Load model
|
| 37 |
model = HindiCharacterCNN(num_labels=36)
|
| 38 |
+
model.load_state_dict(torch.load("your_model.safetensors", map_location=torch.device('cpu')))
|
| 39 |
model.eval()
|
| 40 |
|
| 41 |
+
# Preprocessing
|
| 42 |
+
transform = transforms.Compose([
|
| 43 |
+
transforms.Resize((32, 32)),
|
| 44 |
+
transforms.ToTensor(),
|
| 45 |
+
])
|
| 46 |
+
|
| 47 |
+
st.title("Hindi Character Classification")
|
| 48 |
+
|
| 49 |
+
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
|
| 50 |
+
|
| 51 |
+
if uploaded_file is not None:
|
| 52 |
+
image = Image.open(uploaded_file).convert('RGB')
|
| 53 |
+
st.image(image, caption="Uploaded Image.", use_column_width=True)
|
| 54 |
+
st.write("")
|
| 55 |
+
st.write("Classifying...")
|
| 56 |
+
|
| 57 |
+
image = transform(image).unsqueeze(0)
|
| 58 |
+
|
| 59 |
+
with torch.no_grad():
|
| 60 |
+
output = model(image)
|
| 61 |
+
probabilities = torch.nn.functional.softmax(output[0], dim=0)
|
| 62 |
+
_, predicted_class = torch.max(probabilities, 0)
|
| 63 |
+
st.write(f"Predicted Class: {int(predicted_class)}")
|