user-agent commited on
Commit
06ce79b
·
verified ·
1 Parent(s): fc1f6fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -1
app.py CHANGED
@@ -3,6 +3,7 @@ import base64
3
  import cv2
4
  import numpy as np
5
  import gradio as gr
 
6
  from io import BytesIO
7
 
8
  @spaces.GPU
@@ -40,6 +41,13 @@ def crop_face(base64_image):
40
 
41
  return face_base64
42
 
 
 
 
 
 
 
 
43
  # Define the Gradio interface
44
  interface = gr.Interface(
45
  fn=crop_face,
@@ -49,5 +57,13 @@ interface = gr.Interface(
49
  description="Input a base64 encoded image to get a base64 encoded cropped face."
50
  )
51
 
 
 
 
 
 
 
 
 
52
  if __name__ == "__main__":
53
- interface.launch(share=True)
 
3
  import cv2
4
  import numpy as np
5
  import gradio as gr
6
+ from PIL import Image
7
  from io import BytesIO
8
 
9
  @spaces.GPU
 
41
 
42
  return face_base64
43
 
44
+ def image_to_base64(image):
45
+ # Convert PIL Image to Bytes
46
+ buffered = BytesIO()
47
+ image.save(buffered, format="JPEG")
48
+ img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')
49
+ return img_str
50
+
51
  # Define the Gradio interface
52
  interface = gr.Interface(
53
  fn=crop_face,
 
57
  description="Input a base64 encoded image to get a base64 encoded cropped face."
58
  )
59
 
60
+ interface2 = gr.Interface(
61
+ fn=image_to_base64,
62
+ inputs=gr.inputs.Image(),
63
+ outputs="text",
64
+ title="Image to Base64 Converter",
65
+ description="Upload an image to convert it to Base64 encoded string."
66
+ )
67
+
68
  if __name__ == "__main__":
69
+ gr.TabbedInterface([interface, interface2], ["Crop Face", "Convert to Base64"]).launch(share=True)