Xhaheen commited on
Commit
7cbec0a
β€’
1 Parent(s): 03ded0d

Create app.py

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