import torch from transformers import ViTImageProcessor, ViTForImageClassification from PIL import Image import torch.nn.functional as F import gradio as gr device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') processor = ViTImageProcessor.from_pretrained("ViT_LCZs_v3",local_files_only=True) model = ViTForImageClassification.from_pretrained("ViT_LCZs_v3",local_files_only=True).to(device) def classify_image(image): with torch.no_grad(): model.eval() inputs = processor(images=image, return_tensors="pt") outputs = model(**inputs) logits = outputs.logits prob = torch.nn.functional.softmax(logits, dim=1) top10_prob, top10_indices = torch.topk(prob, 10) top10_confidences = {} for i in range(10): top10_confidences[model.config.id2label[int(top10_indices[0][i])]] = float(top10_prob[0][i]) return top10_confidences #confidences with gr.Blocks(title="ViT LCZ Classification - ClassCat", css=".gradio-container {background:white;}" ) as demo: gr.HTML("""