Spaces:
Runtime error
Runtime error
Update app.py
Browse files123456789101112131415161718192021222324252627282930313233import gradio as grfrom transformers import AutoModelForImageSegmentation, AutoTokenizerimport torchfrom PIL import Image# Load the modelmodel = AutoModelForImageSegmentation.from_pretrained("/absolute/path/to/gelan-c-seg.pt")# Load the tokenizer (if needed)tokenizer = AutoTokenizer.from_pretrained("path/to/tokenizer")# Define the prediction functiondef predict_segmentation(image):# Convert image to PyTorch tensorimage = torch.tensor(image).permute(2, 0, 1).unsqueeze(0).float()# Perform inferenceoutput = model(image)# Process the output as needed (e.g., post-processing for segmentation masks)segmentation_mask = output.logits.argmax(dim=1).squeeze().detach().numpy()return segmentation_mask# Create a Gradio interfaceinputs = gr.inputs.Image(shape=(224, 224))outputs = gr.outputs.Image(type="numpy", label="Segmentation Mask")title = "Image Segmentation Demo"description = "Upload an image and get the segmentation mask."examples = [["example.jpg"]] # Add example images here if neededinterface = gr.Interface(fn=predict_segmentation, inputs=inputs, outputs=outputs, title=title, description=description, examples=examples)# Run the interfaceif __name__ == "__main__":interface.launch()12345678910111213141516import gradio as grimport torchfrom ultralytics import YOLO# Load YOLO modelmodel = YOLO("yolov9c-seg.pt")# Define function to perform predictiondef predict_image(image):result = model.predict(image, show=True, save=True)return result# Create Gradio interfaceimage_input = gr.inputs.Image()gr.Interface(predict_image, image_input, "image").launch()
app.py+10-27