remotewith commited on
Commit
cbae11c
·
1 Parent(s): ed6d97d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -4,6 +4,7 @@ import os
4
  import torch
5
  import numpy as np
6
  from roboflow import Roboflow
 
7
  rf = Roboflow(api_key="gjZE3lykkitagkxHplyJ")
8
  project = rf.workspace().project("rideit")
9
  model = project.version(1).model
@@ -47,10 +48,11 @@ def predict(img) -> Tuple[Dict, float]:
47
  start_time = timer()
48
 
49
  # Transform the target image and add a batch dimension
50
- img1 = effnetb2_transforms(img).unsqueeze(0)
 
51
  pix = normalize_2d(np.array(img))
52
 
53
- pix1=model.predict(str(img.jpg), confidence=40, overlap=30)
54
 
55
 
56
  # Put model into evaluation mode and turn on inference mode
@@ -78,12 +80,20 @@ article = "(https://www.learnpytorch.io/)."
78
  # Create examples list from "examples/" directory
79
  example_list = [["examples/" + example] for example in os.listdir("examples")]
80
 
 
 
 
 
 
 
 
 
81
  # Create the Gradio demo
82
  demo = gr.Interface(fn=predict, # mapping function from input to output
83
- inputs=gr.Image(type="pil"), # what are the inputs?
84
  outputs=[gr.Label(num_top_classes=2, label="Predictions"), # what are the outputs?
85
  gr.Number(label="Prediction time (s)"),
86
- (gr.Image(shape=(300,400)))], # our fn has two outputs, therefore we have two outputs
87
  # Create examples list from "examples/" directory
88
  examples=example_list,
89
  title=title,
 
4
  import torch
5
  import numpy as np
6
  from roboflow import Roboflow
7
+ import cv2
8
  rf = Roboflow(api_key="gjZE3lykkitagkxHplyJ")
9
  project = rf.workspace().project("rideit")
10
  model = project.version(1).model
 
48
  start_time = timer()
49
 
50
  # Transform the target image and add a batch dimension
51
+ img1=PIL.Image.open(img, mode=’r’)
52
+ img1 = effnetb2_transforms(img1).unsqueeze(0)
53
  pix = normalize_2d(np.array(img))
54
 
55
+ pix1=model.predict(img, confidence=40, overlap=30)
56
 
57
 
58
  # Put model into evaluation mode and turn on inference mode
 
80
  # Create examples list from "examples/" directory
81
  example_list = [["examples/" + example] for example in os.listdir("examples")]
82
 
83
+ inputs_image = [
84
+ gr.components.Image(type="filepath", label="Input Image"),
85
+ ]
86
+
87
+ outputs_image = [
88
+ gr.components.Image(type="numpy", label="Output Image"),
89
+ ]
90
+
91
  # Create the Gradio demo
92
  demo = gr.Interface(fn=predict, # mapping function from input to output
93
+ inputs=inputs_image, # what are the inputs?
94
  outputs=[gr.Label(num_top_classes=2, label="Predictions"), # what are the outputs?
95
  gr.Number(label="Prediction time (s)"),
96
+ outputs_image], # our fn has two outputs, therefore we have two outputs
97
  # Create examples list from "examples/" directory
98
  examples=example_list,
99
  title=title,