import gradio as gr import torch import open_clip import joblib def predict(input_image): device = torch.device("cpu") model, _, preprocess = open_clip.create_model_and_transforms('ViT-L-14', pretrained='openai', device=device) image = preprocess(input_image).unsqueeze(0).to(device) with torch.amp.autocast(device_type=device.type): with torch.no_grad(): image_features = model.encode_image(image) image_features /= image_features.norm(dim=-1, keepdim=True) embedding = image_features[0].cpu().float().numpy() model = joblib.load('model.pkl') result = model.predict([embedding]) return "Map" if result == 1 else "No map" demo = gr.Interface(fn=predict, inputs=gr.Image(label="Check whether the image is a map or not", type="pil"), outputs="text") demo.launch()