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)