Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import gradio as gr
|
3 |
+
from datasets import load_dataset
|
4 |
+
|
5 |
+
dataset = load_dataset("laion/laion2B-en-joined")
|
6 |
+
print (type(dataset))
|
7 |
+
|
8 |
+
df = pd.DataFrame(dataset)
|
9 |
+
#df = pd.read_csv("images.csv")
|
10 |
+
|
11 |
+
df['URL'] = df['URL'].apply(lambda x: '<a href= "' + str(x) + '" target="_blank"> <img src= "' + str(x) + '"/> </a>')
|
12 |
+
df = df[[ 'URL', 'TEXT']]
|
13 |
+
|
14 |
+
def display_df():
|
15 |
+
df_images = df.head(100)
|
16 |
+
return df_images
|
17 |
+
|
18 |
+
def display_next100(dataframe, end):
|
19 |
+
dataframe = dataframe.sample(frac=1)
|
20 |
+
start = (end or dataframe.index[-1]) + 1
|
21 |
+
end = start + 99
|
22 |
+
df_images = df.loc[start:end]
|
23 |
+
return df_images, end
|
24 |
+
|
25 |
+
with gr.Blocks() as demo:
|
26 |
+
gr.Markdown("<h1><center>🦁Lion Image Search🎨</center></h1>")
|
27 |
+
gr.Markdown("""<div align="center">Art Descriptions from <a href = "https://huggingface.co/datasets/laion/laion2B-en-joined">Laion</a>. <a href="https://playgroundai.com/create">Create Art Here</a>. <a href="https://paperswithcode.com/datasets?q=art&v=lst&o=newest">Papers,Code,Datasets for SOTA in Art</a>""")
|
28 |
+
|
29 |
+
with gr.Row():
|
30 |
+
num_end = gr.Number(visible=False)
|
31 |
+
b1 = gr.Button("Images with Descriptions 0-100")
|
32 |
+
b2 = gr.Button("Next 100 Images with Descriptions")
|
33 |
+
|
34 |
+
with gr.Row():
|
35 |
+
out_dataframe = gr.Dataframe(wrap=True, max_rows=100, overflow_row_behaviour= "paginate", datatype = ["markdown", "markdown"], headers=['url', 'prompt'])
|
36 |
+
|
37 |
+
b1.click(fn=display_df, outputs=out_dataframe)
|
38 |
+
b2.click(fn=display_next100, inputs= [out_dataframe, num_end ], outputs=[out_dataframe, num_end])
|
39 |
+
|
40 |
+
demo.launch(debug=True, show_error=True)
|