Vincent Claes commited on
Commit
83d644b
•
1 Parent(s): 57d0ffa

make art searching work

Browse files
Files changed (2) hide show
  1. app.py +21 -6
  2. requirements.txt +2 -3
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import gradio as gr
2
  import requests
3
  import base64
@@ -5,20 +6,34 @@ from PIL import Image
5
 
6
  # define the function that will be called when the user inputs text
7
  def get_images(text):
8
- # send the text to the REST API using a POST request
9
- response = requests.post("https://example.com/api/images", json={"text": text})
 
 
 
 
 
 
 
 
 
10
  # get the list of image data from the response
11
- image_data = response.json()["images"]
12
  # decode the base64-encoded image data and convert it to PIL images
13
- images = [Image.open(base64.decodebytes(data)) for data in image_data]
 
 
 
 
14
  # return the list of images
15
  return images
16
 
17
  # create the gradio app, passing the function as the input and output
18
  app = gr.Interface(get_images,
19
  gr.components.Textbox(label="Description"),
20
- gr.components.Image(label="Images", type="pil")
21
- )
 
22
 
23
  # start the app
24
  app.launch()
 
1
+ import io
2
  import gradio as gr
3
  import requests
4
  import base64
 
6
 
7
  # define the function that will be called when the user inputs text
8
  def get_images(text):
9
+ headers = {'Content-Type': 'application/json'}
10
+ params = {
11
+ 'return-images': 'true',
12
+ 'number-results': '4',
13
+ }
14
+ response = requests.post(
15
+ "https://wjdr33c1id.execute-api.eu-west-1.amazonaws.com/dev/prediction",
16
+ params=params,
17
+ headers=headers,
18
+ json={"data": text}
19
+ )
20
  # get the list of image data from the response
21
+ image_data = response.json()["image"]
22
  # decode the base64-encoded image data and convert it to PIL images
23
+ images = [
24
+ Image.open(io.BytesIO(base64.b64decode(data))) for data in image_data
25
+ ]
26
+ # first comes on the top
27
+ images.reverse()
28
  # return the list of images
29
  return images
30
 
31
  # create the gradio app, passing the function as the input and output
32
  app = gr.Interface(get_images,
33
  gr.components.Textbox(label="Description"),
34
+ # gr.components.Image(label="Images", type="pil")
35
+ gr.Gallery(label="Images")
36
+ )
37
 
38
  # start the app
39
  app.launch()
requirements.txt CHANGED
@@ -36,7 +36,7 @@ packaging==22.0
36
  pandas==1.5.2
37
  paramiko==2.12.0
38
  Pillow==9.3.0
39
- pip==22.3
40
  pycparser==2.21
41
  pycryptodome==3.16.0
42
  pydantic==1.10.2
@@ -49,7 +49,6 @@ pytz==2022.6
49
  PyYAML==6.0
50
  requests==2.28.1
51
  rfc3986==1.5.0
52
- setuptools==65.6.3
53
  setuptools-scm==7.0.5
54
  six==1.16.0
55
  sniffio==1.3.0
@@ -60,5 +59,5 @@ uc-micro-py==1.0.1
60
  urllib3==1.26.13
61
  uvicorn==0.20.0
62
  websockets==10.4
63
- wheel==0.37.1
64
  yarl==1.8.2
 
36
  pandas==1.5.2
37
  paramiko==2.12.0
38
  Pillow==9.3.0
39
+ pip==22.3.1
40
  pycparser==2.21
41
  pycryptodome==3.16.0
42
  pydantic==1.10.2
 
49
  PyYAML==6.0
50
  requests==2.28.1
51
  rfc3986==1.5.0
 
52
  setuptools-scm==7.0.5
53
  six==1.16.0
54
  sniffio==1.3.0
 
59
  urllib3==1.26.13
60
  uvicorn==0.20.0
61
  websockets==10.4
62
+ wheel==0.38.4
63
  yarl==1.8.2