Lokesh Jirati commited on
Commit
338c070
·
1 Parent(s): 814fe95

Add application file

Browse files
Files changed (2) hide show
  1. app.py +25 -39
  2. requirements.txt +2 -0
app.py CHANGED
@@ -1,40 +1,26 @@
1
- # ----------- Triton Model Code Starts Below -------------
2
-
3
- import json
4
- import triton_python_backend_utils as pb_utils
5
  import numpy as np
6
-
7
- class TritonPythonModel:
8
- def initialize(self, args):
9
- self.model_config = model_config = json.loads(args["model_config"])
10
-
11
- output0_config = pb_utils.get_output_config_by_name(model_config, "OUTPUT0")
12
- output1_config = pb_utils.get_output_config_by_name(model_config, "OUTPUT1")
13
-
14
- self.output0_dtype = pb_utils.triton_string_to_numpy(output0_config["data_type"])
15
- self.output1_dtype = pb_utils.triton_string_to_numpy(output1_config["data_type"])
16
-
17
- def execute(self, requests):
18
- output0_dtype = self.output0_dtype
19
- output1_dtype = self.output1_dtype
20
- responses = []
21
-
22
- for request in requests:
23
- in_0 = pb_utils.get_input_tensor_by_name(request, "INPUT0")
24
- in_1 = pb_utils.get_input_tensor_by_name(request, "INPUT1")
25
-
26
- out_0 = in_0.as_numpy() + in_1.as_numpy()
27
- out_1 = in_0.as_numpy() - in_1.as_numpy()
28
-
29
- out_tensor_0 = pb_utils.Tensor("OUTPUT0", out_0.astype(output0_dtype))
30
- out_tensor_1 = pb_utils.Tensor("OUTPUT1", out_1.astype(output1_dtype))
31
-
32
- inference_response = pb_utils.InferenceResponse(
33
- output_tensors=[out_tensor_0, out_tensor_1]
34
- )
35
- responses.append(inference_response)
36
-
37
- return responses
38
-
39
- def finalize(self):
40
- print("Cleaning up...")
 
 
 
 
 
1
  import numpy as np
2
+ import gradio as gr
3
+
4
+ def add_and_subtract(input0, input1):
5
+ input0 = np.array(input0)
6
+ input1 = np.array(input1)
7
+
8
+ out0 = input0 + input1
9
+ out1 = input0 - input1
10
+ return out0.tolist(), out1.tolist()
11
+
12
+ iface = gr.Interface(
13
+ fn=add_and_subtract,
14
+ inputs=[
15
+ gr.Textbox(label="Input 0 (comma-separated numbers)"),
16
+ gr.Textbox(label="Input 1 (comma-separated numbers)")
17
+ ],
18
+ outputs=[
19
+ gr.Textbox(label="Output 0 (Sum)"),
20
+ gr.Textbox(label="Output 1 (Difference)")
21
+ ],
22
+ title="Add and Subtract Arrays"
23
+ )
24
+
25
+ if __name__ == "__main__":
26
+ iface.launch()
 
 
 
 
 
 
 
 
 
 
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ numpy