Image Classification
Transformers
Safetensors
vit
vision transformer
agriculture
plant disease detection
smart farming
image classification
Instructions to use aashituli/promblemo with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use aashituli/promblemo with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="aashituli/promblemo") pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png")# Load model directly from transformers import AutoImageProcessor, AutoModelForImageClassification processor = AutoImageProcessor.from_pretrained("aashituli/promblemo") model = AutoModelForImageClassification.from_pretrained("aashituli/promblemo") - Notebooks
- Google Colab
- Kaggle
| from fastapi import FastAPI, File, UploadFile, Request | |
| from fastapi.responses import HTMLResponse, JSONResponse | |
| from fastapi.staticfiles import StaticFiles | |
| from fastapi.templating import Jinja2Templates | |
| from PIL import Image | |
| import torch | |
| from transformers import AutoImageProcessor, AutoModelForImageClassification | |
| import io | |
| app = FastAPI() | |
| # Load model and processor once | |
| processor = AutoImageProcessor.from_pretrained("aashituli/promblemo") | |
| model = AutoModelForImageClassification.from_pretrained("aashituli/promblemo") | |
| # Mount templates and static files | |
| app.mount("/static", StaticFiles(directory="static"), name="static") | |
| templates = Jinja2Templates(directory="templates") | |
| async def home(request: Request): | |
| return templates.TemplateResponse("index.html", {"request": request}) | |
| async def predict(file: UploadFile = File(...)): | |
| try: | |
| contents = await file.read() | |
| image = Image.open(io.BytesIO(contents)).convert("RGB") | |
| inputs = processor(images=image, return_tensors="pt") | |
| with torch.no_grad(): | |
| outputs = model(**inputs) | |
| predicted_class_idx = outputs.logits.argmax(-1).item() | |
| predicted_class = model.config.id2label[predicted_class_idx] | |
| return JSONResponse(content={"prediction": predicted_class}) | |
| except Exception as e: | |
| return JSONResponse(content={"error": str(e)}, status_code=500) | |