Spaces:
Sleeping
Sleeping
Oliver Hamilton
commited on
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,17 +1,10 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
# import torch
|
| 3 |
-
# import requests
|
| 4 |
-
# from torchvision import transforms
|
| 5 |
import cv2
|
| 6 |
from geti_sdk.deployment import Deployment
|
| 7 |
from geti_sdk.utils import show_image_with_annotation_scene
|
| 8 |
|
| 9 |
-
# model = torch.hub.load("pytorch/vision:v0.6.0", "resnet18", pretrained=True).eval()
|
| 10 |
-
# response = requests.get("https://git.io/JJkYN")
|
| 11 |
-
# labels = response.text.split("\n")
|
| 12 |
|
| 13 |
-
|
| 14 |
-
# Step 1: Load the deployment
|
| 15 |
deployment = Deployment.from_folder("deployment")
|
| 16 |
deployment.load_inference_models(device="CPU")
|
| 17 |
|
|
@@ -31,27 +24,14 @@ def infer(image=None):
|
|
| 31 |
return [None,'Error: No image provided']
|
| 32 |
|
| 33 |
image = resize_image(image, 1200)
|
| 34 |
-
|
|
|
|
| 35 |
output = show_image_with_annotation_scene(image, prediction, show_results=False)
|
| 36 |
output = cv2.cvtColor(output, cv2.COLOR_RGB2BGR)
|
| 37 |
return [output, prediction.overview]
|
| 38 |
|
| 39 |
|
| 40 |
-
# def predict(inp):
|
| 41 |
-
# inp = transforms.ToTensor()(inp).unsqueeze(0)
|
| 42 |
-
# with torch.no_grad():
|
| 43 |
-
# prediction = torch.nn.functional.softmax(model(inp)[0], dim=0)
|
| 44 |
-
# confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
|
| 45 |
-
# return confidences
|
| 46 |
-
|
| 47 |
-
|
| 48 |
def run():
|
| 49 |
-
# demo = gr.Interface(
|
| 50 |
-
# fn=predict,
|
| 51 |
-
# inputs=gr.inputs.Image(type="pil"),
|
| 52 |
-
# outputs=gr.outputs.Label(num_top_classes=3),
|
| 53 |
-
# )
|
| 54 |
-
|
| 55 |
demo = gr.Interface(fn=infer,
|
| 56 |
inputs=['image'],
|
| 57 |
outputs=['image', 'text'],
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
import cv2
|
| 3 |
from geti_sdk.deployment import Deployment
|
| 4 |
from geti_sdk.utils import show_image_with_annotation_scene
|
| 5 |
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
#Load the deployment
|
|
|
|
| 8 |
deployment = Deployment.from_folder("deployment")
|
| 9 |
deployment.load_inference_models(device="CPU")
|
| 10 |
|
|
|
|
| 24 |
return [None,'Error: No image provided']
|
| 25 |
|
| 26 |
image = resize_image(image, 1200)
|
| 27 |
+
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
| 28 |
+
prediction = deployment.infer(image_rgb)
|
| 29 |
output = show_image_with_annotation_scene(image, prediction, show_results=False)
|
| 30 |
output = cv2.cvtColor(output, cv2.COLOR_RGB2BGR)
|
| 31 |
return [output, prediction.overview]
|
| 32 |
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
def run():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
demo = gr.Interface(fn=infer,
|
| 36 |
inputs=['image'],
|
| 37 |
outputs=['image', 'text'],
|