Rakesh443 commited on
Commit
771240c
·
verified ·
1 Parent(s): 01c0511

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -5,7 +5,9 @@ import requests
5
  import io
6
  from PIL import Image
7
  import os
8
- import matplotlib.image as mpimg
 
 
9
  # Create a text input
10
 
11
  api_key = os.getenv("ImageGenerating")
@@ -26,12 +28,16 @@ image_bytes = query({
26
  "inputs": user_input,
27
  })
28
 
29
- def bytes_to_image_matplotlib(byte_data):
30
- image = mpimg.imread(io.BytesIO(byte_data), format='PNG')
 
31
  return image
32
- image = bytes_to_image_matplotlib(image_bytes)
 
 
 
33
  # image = Image.open(io.BytesIO(image_bytes))
34
- st.image(image, caption=None, width=None, use_column_width=None, clamp=False, channels="RGB", output_format="PNG")
35
  # st.image(image=image,caption="image")
36
  # st.image(image)
37
  # st.image(image : image,caption=image)
 
5
  import io
6
  from PIL import Image
7
  import os
8
+ import cv2
9
+ import numpy as np
10
+
11
  # Create a text input
12
 
13
  api_key = os.getenv("ImageGenerating")
 
28
  "inputs": user_input,
29
  })
30
 
31
+ def bytes_to_image_opencv(image_bytes):
32
+ np_arr = np.frombuffer(image_bytes, np.uint8)
33
+ image = cv2.imdecode(np_arr, cv2.IMREAD_COLOR)
34
  return image
35
+
36
+ result_image_opencv = bytes_to_image_opencv(image_bytes)
37
+ st.image(result_image_opencv,caption="image")
38
+
39
  # image = Image.open(io.BytesIO(image_bytes))
40
+ # st.image(image, caption=None, width=None, use_column_width=None, clamp=False, channels="RGB", output_format="PNG")
41
  # st.image(image=image,caption="image")
42
  # st.image(image)
43
  # st.image(image : image,caption=image)