Xhaheen commited on
Commit
90ec7f3
β€’
1 Parent(s): eeb9b12

Create lexica.py

Browse files
Files changed (1) hide show
  1. lexica.py +82 -0
lexica.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import shutil
3
+ from PIL import Image
4
+ from io import BytesIO
5
+ import numpy as np
6
+ import matplotlib.pyplot as plt
7
+ import pandas as pd
8
+ import random
9
+ import gradio as gr
10
+
11
+ design='india'
12
+ def lexica(design,n):
13
+
14
+ request=requests.get(f'https://lexica.art/api/v1/search?q={design}')
15
+ request.json()
16
+ data = request.json()
17
+ data_items = list(data.items())
18
+
19
+ random.shuffle(data_items)
20
+
21
+ data = dict(data_items)
22
+
23
+ image_urls = []
24
+ image_prompts = []
25
+
26
+ for key, value in data.items():
27
+ for i in range(n):
28
+ image_url = value[i]['src']
29
+ if isinstance(image_url, list):
30
+ image_url = image_url[0]
31
+ image_urls.append(image_url)
32
+
33
+
34
+ image_prompts.append(value[i]['prompt'])
35
+
36
+ images = []
37
+
38
+ # Loop through the image URLs
39
+ for url in image_urls:
40
+ # Download the image from the URL
41
+ response = requests.get(url)
42
+
43
+ # Load the image data into PIL format
44
+ image = Image.open(BytesIO(response.content))
45
+
46
+ # Add the image to the list
47
+ images.append(image)
48
+
49
+
50
+ df = pd.DataFrame(image_prompts, columns=["Lexica Prompt"], index=range(1, len(image_prompts)+1))
51
+
52
+
53
+ df.index.name = "Sr. No."
54
+
55
+
56
+ for image in images:
57
+
58
+ array = np.array(image)
59
+
60
+
61
+ return images , df
62
+ design='india'
63
+ # lexica(design)
64
+
65
+ inputs =[ gr.Textbox(label = 'Enter prompt to search Lexica.art'),
66
+ gr.Slider(label='Number of images ', minimum = 4, maximum = 20, step = 1, value = 4)]
67
+
68
+ outputs= [gr.Gallery(lable='Output gallery').style(grid=1),
69
+ gr.Dataframe(label='prompts for corresponding images')]
70
+
71
+ # Create and launch the interface
72
+ interface = gr.Interface(lexica,
73
+ inputs=inputs,
74
+ outputs=outputs,
75
+ examples =[ ['trending digital art', 5],
76
+ ['beautiful home', 5],
77
+ ['interior design of living room', 5]]
78
+ ,
79
+ title = "" +' πŸ” πŸ–ŒοΈπŸŽ¨ Lexica Art - A Search Engine for Generative Art Prompts and Works '+ "",
80
+ 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. πŸ’‘πŸ–ŒοΈ spaces built with ❀️ @[Xhaheen](https://www.linkedin.com/in/sallu-mandya)")
81
+
82
+ interface.launch(debug=True)