File size: 2,968 Bytes
90ec7f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
375b896
90ec7f3
 
 
 
 
 
 
 
 
 
375b896
90ec7f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
375b896
90ec7f3
 
375b896
69f21fb
0b6c91b
 
90ec7f3
0b6c91b
 
90ec7f3
 
 
 
 
 
 
 
 
 
 
 
 
9f80096
03ded0d
9f80096
90ec7f3
 
 
 
 
 
 
 
 
 
3fae3d0
90ec7f3
 
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
83
84
85
86
87
88
89
90
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 = []
  image_gallery=[]

  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'])
      image_gallery.append(value[i]['gallery'])
 
  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."
  df = pd.DataFrame({ 'image_gallery': image_gallery,'image_prompts': image_prompts})
  def make_clickable(val):
    return '<a href="{}">{}</a>'.format(val, val)

  # df.style.format({'image_gallery': make_clickable})
  df.style.format({'image_prompts': make_clickable}).set_properties(subset=['image_prompts'], width=30)
 
  for image in images:
 
    array = np.array(image)

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

inputs =[ gr.Textbox(label = 'Enter prompt to search Lexica.art'),
         gr.Slider(label='Number of images ', minimum = 4, maximum = 20, step = 1, value = 4)]
 
 
outputs=     [gr.Gallery(lable='Output gallery').style(grid=4,height=100,container=True),
              gr.Dataframe(label='links and 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 = "" +' πŸ” πŸ–ŒοΈπŸŽ¨ Lexica Art - A Search Engine for Generative Art Prompts and Works '+ "",
     description="πŸ”πŸ–ŒοΈ 🎨 lexica huggingface space  , Find inspiration and discover new generative artworks with Lexica Art, a search engine built  by  by @[Sharif shameem](https://twitter.com/sharifshameem) . Explore a vast collection of prompts and corresponding artworks, and let your imagination take over as you create your own masterpieces. \n\n Visit @[baith_al_suroor](https://huggingface.co./spaces/Xhaheen/Baith-al-suroor) to redesign your home interiors for FREE  \n\nπŸ’‘πŸ–ŒοΈ spaces built with ❀️   @[Xhaheen](https://www.linkedin.com/in/sallu-mandya)")

interface.launch(debug=True)