File size: 1,250 Bytes
83d644b
57d0ffa
 
 
 
 
 
 
83d644b
 
 
 
 
 
 
 
 
 
 
57d0ffa
83d644b
57d0ffa
83d644b
 
 
 
 
57d0ffa
 
 
 
 
 
83d644b
 
 
57d0ffa
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import io
import gradio as gr
import requests
import base64
from PIL import Image

# define the function that will be called when the user inputs text
def get_images(text):
  headers = {'Content-Type': 'application/json'}
  params = {
      'return-images': 'true',
      'number-results': '4',
  }
  response = requests.post(
                            "https://wjdr33c1id.execute-api.eu-west-1.amazonaws.com/dev/prediction", 
                            params=params, 
                            headers=headers, 
                            json={"data": text}
                          )
  # get the list of image data from the response
  image_data = response.json()["image"]
  # decode the base64-encoded image data and convert it to PIL images
  images = [
    Image.open(io.BytesIO(base64.b64decode(data))) for data in image_data
    ]
  # first comes on the top
  images.reverse()
  # return the list of images
  return images

# create the gradio app, passing the function as the input and output
app = gr.Interface(get_images,
                   gr.components.Textbox(label="Description"),
                  #  gr.components.Image(label="Images", type="pil")
                   gr.Gallery(label="Images")
)

# start the app
app.launch()