Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import onnxruntime as ort
|
| 4 |
+
from matplotlib import pyplot as plt
|
| 5 |
+
from huggingface_hub import hf_hub_download
|
| 6 |
+
|
| 7 |
+
model = hf_hub_download(repo_id="matjesg/cFOS_in_HC", filename="ensemble.onnx")
|
| 8 |
+
|
| 9 |
+
def create_model_for_provider(model_path, provider="CPUExecutionProvider"):
|
| 10 |
+
options = ort.SessionOptions()
|
| 11 |
+
options.intra_op_num_threads = 1
|
| 12 |
+
options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_ALL
|
| 13 |
+
session = ort.InferenceSession(str(model_path), options, providers=[provider])
|
| 14 |
+
session.disable_fallback()
|
| 15 |
+
return session
|
| 16 |
+
|
| 17 |
+
ort_session = create_model_for_provider(model)
|
| 18 |
+
|
| 19 |
+
def inference(img):
|
| 20 |
+
|
| 21 |
+
img = img[...,:1]/255
|
| 22 |
+
|
| 23 |
+
ort_inputs = {ort_session.get_inputs()[0].name: img.astype(np.float32)}
|
| 24 |
+
|
| 25 |
+
ort_outs = ort_session.run(None, ort_inputs)
|
| 26 |
+
|
| 27 |
+
return ort_outs[0]*255
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
title="deepflash2"
|
| 31 |
+
description="deepflash2 is a deep-learning pipeline for segmentation of ambiguous microscopic images."
|
| 32 |
+
examples=[['1599.tif']]
|
| 33 |
+
|
| 34 |
+
gr.Interface(inference,
|
| 35 |
+
gr.inputs.Image(type="numpy"),
|
| 36 |
+
gr.outputs.Image(),
|
| 37 |
+
title=title,
|
| 38 |
+
description=description,
|
| 39 |
+
examples=examples
|
| 40 |
+
).launch(share=True)
|