File size: 2,081 Bytes
3ae10a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import requests
import shutil
from PIL import Image
from io import BytesIO
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import random
import gradio as gr
 
design='india'
def lexica(design,n):

  request=requests.get(f'https://lexica.art/api/v1/search?q={design}')
  request.json()
  data = request.json()
  data_items = list(data.items())

  random.shuffle(data_items)

  data = dict(data_items)

  image_urls = []
  image_prompts = []

  for key, value in data.items():
    for i in range(n):
      image_url = value[i]['src']
      if isinstance(image_url, list):
        image_url = image_url[0]
      image_urls.append(image_url)

 
      image_prompts.append(value[i]['prompt'])
 
  images = []

  # Loop through the image URLs
  for url in image_urls:
    # Download the image from the URL
    response = requests.get(url)

    # Load the image data into PIL format
    image = Image.open(BytesIO(response.content))

    # Add the image to the list
    images.append(image)

 
  df = pd.DataFrame(image_prompts, columns=["Lexica Prompt"], index=range(1, len(image_prompts)+1))

 
  df.index.name = "Sr. No."

 
  for image in images:
 
    array = np.array(image)

 
  return images , df
design='india'
# lexica(design)

inputs =[ gr.Textbox(label = 'Enter prompt to search'),
         gr.Slider(label='Number of images ', minimum = 4, maximum = 20, step = 1, value = 4)]
 
outputs=     [gr.Gallery(lable='Output gallery').style(grid=1),
              gr.Dataframe(label='prompts for corresponding images')]

# Create and launch the interface
interface = gr.Interface(lexica,
    inputs=inputs,
    outputs=outputs,
    examples =[ ['trending digital art', 5],
                  ['beautiful home', 5],
               ['interior design of living room', 5]]
                  ,
     title = "" +' A Search Engine for Generative Art Prompts and Works '+ "",
     description=" Find more powerful tools at [AI Beast](https://aibeast.net) and follow for updates . [Follow](https://www.facebook.com/abbas143office)  ❤️")

interface.launch(debug=True)