Update app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647# '''# contains the infernce code for fastsam.py# '''# import numpy as np# import gradio as gr# from PIL import Image# from ultralytics import FastSAM# from ultralytics.models.fastsam import FastSAMPrompt# def inference(image):# model = FastSAM('FastSAM.pt')# ## inference results# # Run inference on an image# results = model(source, device='cpu', retina_masks=True, imgsz=1024, conf=0.4, iou=0.9)# # Prepare a Prompt Process object# prompt_process = FastSAMPrompt(source, results, device='cpu')# # Everything prompt# ann = prompt_process.everything_prompt()# # Bbox default shape [0,0,0,0] -> [x1,y1,x2,y2]# ann = prompt_process.box_prompt(bbox=[200, 200, 300, 300])# # Text prompt# ann = prompt_process.text_prompt(text='a photo of a dog')# # Bbox default shape [0,0,0,0] -> [x1,y1,x2,y2]# ann = prompt_process.point_prompt(points=[[200,200]],pointlabel=[1])# prompt_process.plot(annotations=ann,output='./')# title = "Usage of FastSAM"# description = "Implementation of pre-trained fast-sam model for spaces."# demo = gr.Interface(inference,inputs=[gr.Image(shape=(32,32),labels="Input Image"),"checkbox"],# outputs = [gr.Image(shape=(32,32),label='Output').style(width=128,height=128)],# title = title,# description = description)# demo.launch(debug = True)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748'''contains the infernce code for fastsam.py'''import numpy as npimport gradio as grfrom PIL import Imagefrom ultralytics import FastSAMfrom ultralytics.models.fastsam import FastSAMPromptdef inference(image):model = FastSAM('FastSAM.pt')## inference results# Run inference on an imageresults = model(source, device='cpu', retina_masks=True, imgsz=1024, conf=0.4, iou=0.9)# Prepare a Prompt Process objectprompt_process = FastSAMPrompt(source, results, device='cpu')# Everything promptann = prompt_process.everything_prompt()# Bbox default shape [0,0,0,0] -> [x1,y1,x2,y2]ann = prompt_process.box_prompt(bbox=[200, 200, 300, 300])# Text promptann = prompt_process.text_prompt(text='a photo of a dog')# Bbox default shape [0,0,0,0] -> [x1,y1,x2,y2]ann = prompt_process.point_prompt(points=[[200,200]],pointlabel=[1])return prompt_process.plot(annotations=ann,output='./')title = "Usage of FastSAM"description = "Implementation of pre-trained fast-sam model for spaces."demo = gr.Interface(inference,inputs=[gr.Image(shape=(32,32),labels="Input Image"),"checkbox"],outputs = [gr.Image(shape=(32,32),label='Output').style(width=128,height=128)],title = title,description = description)demo.launch(debug = True)
app.py+32-31