DanielFD commited on
Commit
569320d
·
1 Parent(s): ad31722

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +40 -0
  2. requirements.txt +8 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ from io import BytesIO
4
+ import base64
5
+ import matplotlib.image as mpimg
6
+ import cv2
7
+
8
+ def string_to_img(base64_string):
9
+ imgdata = base64.b64decode(base64_string + '==')
10
+ im = BytesIO(imgdata)
11
+ img = mpimg.imread(im, format='PNG')
12
+ opencv_img= cv2.cvtColor(np.array(img), cv2.COLOR_BGR2RGB)
13
+ return opencv_img
14
+
15
+ def img_to_string(img):
16
+ _, encoded_img = cv2.imencode('.PNG', img)
17
+ base64_string = base64.b64encode(encoded_img).decode('utf-8')
18
+ return base64_string
19
+
20
+ def api_image_processing(image):
21
+ # API Endpoint
22
+ url = "http://18.132.59.76/fmc_api"
23
+ # Step 1
24
+ b64_string = img_to_string(image)
25
+ # Step 2
26
+ payload ={"base64_string": b64_string}
27
+ base64_string_resp = requests.post(url=url, data=payload)
28
+ # Step 3
29
+ img_output = string_to_img(base64_string_resp)
30
+ # Return processed image
31
+ return img_output
32
+
33
+ demo = gr.Interface(
34
+ api_image_processing,
35
+ gr.Image(source="webcam", streaming=True),
36
+ "image",
37
+ live=True
38
+ )
39
+
40
+ demo.launch(share=True, debug=True)
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ Flask==2.0.1
2
+ gradio==3.16.2
3
+ ipython==8.8.0
4
+ matplotlib==3.6.2
5
+ mediapipe==0.9.0.1
6
+ numpy==1.21.5
7
+ opencv_contrib_python==4.7.0.68
8
+ requests==2.28.1