Spaces:
Runtime error
Runtime error
Create app.py
Browse files123456789101112131415161718192021222324252627282930313233import gradio as grfrom transformers import AutoModelForImageSegmentation, AutoTokenizerimport torchfrom PIL import Image
# Load the modelmodel = AutoModelForImageSegmentation.from_pretrained("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 tensor image = torch.tensor(image).permute(2, 0, 1).unsqueeze(0).float() # Perform inference output = model(image) # Process the output as needed (e.g., post-processing for segmentation masks) # (Replace this with your actual processing code) 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()app.pyAdded+33