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
File size: 1,449 Bytes
1db8d5a | 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 | 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")
@app.get("/", response_class=HTMLResponse)
async def home(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
@app.post("/predict/")
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)
|