@@ -334,40 +334,98 @@ apptainer pull --dir . --disable-cache docker://ericup/celldetection:latest
334334
335335Find us on Hugging Face and upload your own images for segmentation: https://huggingface.co/spaces/ericup/celldetection
336336
337+ There's also an API (Python & JavaScript), allowing you to utilize community GPUs (currently Nvidia A100) remotely!
338+
337339<details >
338340 <summary style="font-weight: bold; color: #888888">Hugging Face API</summary>
339341
340342### Python
341343
342344``` python
343- import requests
344-
345- response = requests.post(" https://ericup-celldetection.hf.space/run/predict" , json = {
346- " data" : [
347- " data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==" ,
348- " ginoro_CpnResNeXt101UNet-fbe875f1a3e5ce2c" ,
349- ]
350- }).json()
351-
352- data = response[" data" ]
345+ from gradio_client import Client
346+
347+ # Define inputs (local filename or URL)
348+ inputs = ' https://raw.githubusercontent.com/scikit-image/scikit-image/main/skimage/data/coins.png'
349+
350+ # Set up client
351+ client = Client(" ericup/celldetection" )
352+
353+ # Predict
354+ overlay_filename, img_filename, h5_filename, csv_filename = client.predict(
355+ inputs, # str: Local filepath or URL of your input image
356+
357+ # Model name
358+ ' ginoro_CpnResNeXt101UNet-fbe875f1a3e5ce2c' ,
359+
360+ # Custom Score Threshold (numeric value between 0 and 1)
361+ False , .9 , # bool: Whether to use custom setting; float: Custom setting
362+
363+ # Custom NMS Threshold
364+ False , .3142 , # bool: Whether to use custom setting; float: Custom setting
365+
366+ # Custom Number of Sample Points
367+ False , 128 , # bool: Whether to use custom setting; int: Custom setting
368+
369+ # Overlapping objects
370+ True , # bool: Whether to allow overlapping objects
371+
372+ # API name (keep as is)
373+ api_name = " /predict"
374+ )
375+
376+
377+ # Example usage: Code below only shows how to use the results
378+ from matplotlib import pyplot as plt
379+ import celldetection as cd
380+ import pandas as pd
381+
382+ # Read results from local temporary files
383+ img = imread(img_filename)
384+ overlay = imread(overlay_filename) # random colors per instance; transparent overlap
385+ properties = pd.read_csv(csv_filename)
386+ contours, scores, label_image = cd.from_h5(h5_filename, ' contours' , ' scores' , ' labels' )
387+
388+ # Optionally display overlay
389+ cd.imshow_row(img, img, figsize = (16 , 9 ))
390+ cd.imshow(overlay)
391+ plt.show()
392+
393+ # Optionally display contours with text
394+ cd.imshow_row(img, img, figsize = (16 , 9 ))
395+ cd.plot_contours(contours, texts = [' score: %d%% \n area: %d ' % s for s in zip ((scores * 100 ).round(), properties.area)])
396+ plt.show()
353397```
354398
355399### Javascript
356400
357401``` javascript
358- const response = await fetch (" https://ericup-celldetection.hf.space/run/predict" , {
359- method: " POST" ,
360- headers: {" Content-Type" : " application/json" },
361- body: JSON .stringify ({
362- data: [
363- " data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==" ,
364- " ginoro_CpnResNeXt101UNet-fbe875f1a3e5ce2c" ,
365- ]
366- })
367- });
368-
369- const data = await response .json ();
370-
402+ import { client } from " @gradio/client" ;
403+
404+ const response_0 = await fetch (" https://raw.githubusercontent.com/scikit-image/scikit-image/main/skimage/data/coins.png" );
405+ const exampleImage = await response_0 .blob ();
406+
407+ const app = await client (" ericup/celldetection" );
408+ const result = await app .predict (" /predict" , [
409+ exampleImage, // blob: Your input image
410+
411+ // Model name (hosted model or URL)
412+ " ginoro_CpnResNeXt101UNet-fbe875f1a3e5ce2c" ,
413+
414+ // Custom Score Threshold (numeric value between 0 and 1)
415+ false , .9 , // bool: Whether to use custom setting; float: Custom setting
416+
417+ // Custom NMS Threshold
418+ false , .3142 , // bool: Whether to use custom setting; float: Custom setting
419+
420+ // Custom Number of Sample Points
421+ false , 128 , // bool: Whether to use custom setting; int: Custom setting
422+
423+ // Overlapping objects
424+ true , // bool: Whether to allow overlapping objects
425+
426+ // API name (keep as is)
427+ api_name= " /predict"
428+ ]);
371429```
372430
373431</details >
0 commit comments