# import gradio as gr # # Use a pipeline as a high-level helper # from transformers import pipeline # # Use a pipeline as a high-level helper # # Load model directly # from transformers import AutoImageProcessor, AutoModelForImageClassification # # processor = AutoImageProcessor.from_pretrained("AZIIIIIIIIZ/vit-base-patch16-224-finetuned-eurosat") # # model = AutoModelForImageClassification.from_pretrained("AZIIIIIIIIZ/vit-base-patch16-224-finetuned-eurosat") # pipe = pipeline("image-classification", model="AZIIIIIIIIZ/vit-base-patch16-224-finetuned-eurosat") # # $ pip install gradio_client fastapi uvicorn # import requests # from PIL import Image # from transformers import pipeline # import io # import base64 # Initialize the pipeline # pipe = pipeline('image-classification') # def load_image_from_path(image_path): # return Image.open(image_path) # def load_image_from_url(image_url): # response = requests.get(image_url) # return Image.open(io.BytesIO(response.content)) # def load_image_from_base64(base64_string): # image_data = base64.b64decode(base64_string) # return Image.open(io.BytesIO(image_data)) # def predict(image_input): # if isinstance(image_input, str): # if image_input.startswith('http'): # image = load_image_from_url(image_input) # elif image_input.startswith('/'): # image = load_image_from_path(image_input) # else: # image = load_image_from_base64(image_input) # elif isinstance(image_input, Image.Image): # image = image_input # else: # raise ValueError("Incorrect format used for image. Should be an URL linking to an image, a base64 string, a local path, or a PIL image.") # return pipe(image) # def predict(image): # return pipe(image) # def main(): # # image_input = 'path_or_url_or_base64' # Update with actual input # # output = predict(image_input) # # print(output) # demo = gr.Interface( # fn=predict, # inputs='image', # outputs='text', # ) # demo.launch() # import requests # import torch # from PIL import Image # from torchvision import transforms # def predict(inp): # inp = Image.fromarray(inp.astype("uint8"), "RGB") # inp = transforms.ToTensor()(inp).unsqueeze(0) # with torch.no_grad(): # prediction = torch.nn.functional.softmax(model(inp.to(device))[0], dim=0) # return {labels[i]: float(prediction[i]) for i in range(1000)} # inputs = gr.Image() # outputs = gr.Label(num_top_classes=2) # io = gr.Interface( # fn=predict, inputs=inputs, outputs=outputs, examples=["dog.jpg"] # ) # io.launch(inline=False, share=True) # import gradio as gr # from transformers import pipeline # pipeline = pipeline("image-classification", model="AZIIIIIIIIZ/vit-base-patch16-224-finetuned-eurosat") # def predict(image): # predictions = pipeline(image) # return {p["label"]: p["score"] for p in predictions} # gr.Interface( # predict, # inputs=gr.inputs.Image(label="Upload Image", type="filepath"), # outputs=gr.outputs.Label(num_top_classes=2), # title="AI Generated? Or Not?", # allow_flagging="manual" # ).launch() # if __name__ == "__main__": # main() import gradio as gr from transformers import pipeline pipeline = pipeline("image-classification", model="AZIIIIIIIIZ/vit-base-patch16-224-finetuned-eurosat") def predict(input_img): predictions = pipeline(input_img) return input_img, {p["label"]: p["score"] for p in predictions} gradio_app = gr.Interface( predict, inputs=gr.Image(label="Select hot dog candidate", sources=['upload', 'webcam'], type="pil"), outputs=[gr.Image(label="Processed Image"), gr.Label(label="Result", num_top_classes=2)], title="Hot Dog? Or Not?", ) if __name__ == "__main__": gradio_app.launch()