taesiri commited on
Commit
a47b2ba
·
1 Parent(s): 32117d6
Files changed (1) hide show
  1. app.py +73 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from datasets import load_dataset
3
+ from PIL import Image
4
+ import io
5
+ import time
6
+
7
+ # Load and prepare the dataset
8
+ dataset = load_dataset(
9
+ "taesiri/PhotoshopRequest-DailyDump", split="train", streaming=True
10
+ )
11
+
12
+ BUFFER_SIZE = 1
13
+ sample_iterator = None
14
+ sample_count = 0
15
+
16
+
17
+ def reshuffle_dataset():
18
+ global sample_iterator, sample_count
19
+ seed = int(time.time()) # Convert time to an integer
20
+ shuffled_dataset = dataset.shuffle(seed=seed, buffer_size=BUFFER_SIZE)
21
+ sample_iterator = iter(shuffled_dataset)
22
+ sample_count = 0
23
+
24
+
25
+ reshuffle_dataset() # Initial shuffle
26
+
27
+
28
+ def get_next_sample():
29
+ global sample_count
30
+
31
+ if sample_count >= BUFFER_SIZE:
32
+ reshuffle_dataset()
33
+
34
+ sample = next(sample_iterator)
35
+ sample_count += 1
36
+
37
+ post_id = sample["post_id"]
38
+ title = sample["title"]
39
+ reddit_url = f"https://www.reddit.com/r/PhotoshopRequest/comments/{post_id}"
40
+ markdown_text = f"# {title}\n\n[View post on r/PhotoshopRequest]({reddit_url})"
41
+
42
+ return (
43
+ markdown_text,
44
+ sample["source_image"],
45
+ sample["edited_image"],
46
+ )
47
+
48
+
49
+ with gr.Blocks() as demo:
50
+ gr.Markdown("# PhotoshopRequest Dataset Sampler")
51
+
52
+ gr.Markdown(
53
+ """
54
+ This is a preview of the PhotoshopRequest dataset. Each sample represents a Photoshop editing request post.
55
+ Click the 'Sample New Item' button to retrieve a random sample from the dataset.
56
+ </hr>
57
+ """
58
+ )
59
+
60
+ post_info = gr.Markdown()
61
+
62
+ with gr.Row():
63
+ source_image = gr.Image(label="Source Image")
64
+ edited_image = gr.Image(label="Edited Image")
65
+
66
+ sample_button = gr.Button("Sample New Item")
67
+
68
+ sample_button.click(
69
+ get_next_sample, outputs=[post_info, source_image, edited_image]
70
+ )
71
+
72
+ if __name__ == "__main__":
73
+ demo.launch()