Spaces:
Sleeping
Sleeping
hugfaceguy0001
commited on
Commit
β’
08fee89
1
Parent(s):
e20d622
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from datasets import load_dataset
|
3 |
+
import random
|
4 |
+
|
5 |
+
dataset = load_dataset("hugfaceguy0001/TangshiDalle3Images")['train']
|
6 |
+
demo = gr.Blocks(theme=gr.themes.Default(text_size="lg"))
|
7 |
+
N = random.randint(0,230)
|
8 |
+
j = 3 * N + 1
|
9 |
+
poem_text = dataset[j]['prompt']
|
10 |
+
poem_info = dataset[j+1]['prompt']
|
11 |
+
poem_title = poem_info[poem_info.index("γ")+1:poem_info.index("γ")]
|
12 |
+
poem_author = poem_info[3:poem_info.index("η")]
|
13 |
+
poem = f" {poem_title} {poem_author}\n{poem_text}"
|
14 |
+
k = j + random.randint(-1,1)
|
15 |
+
poem_image = dataset[k]['image']
|
16 |
+
def random_poem():
|
17 |
+
global N
|
18 |
+
global j
|
19 |
+
global k
|
20 |
+
N = random.randint(0,230)
|
21 |
+
j = 3 * N + 1
|
22 |
+
poem_text = dataset[j]['prompt']
|
23 |
+
poem_info = dataset[j+1]['prompt']
|
24 |
+
poem_title = poem_info[poem_info.index("γ")+1:poem_info.index("γ")]
|
25 |
+
poem_author = poem_info[3:poem_info.index("η")]
|
26 |
+
poem = f" {poem_title} {poem_author}\n{poem_text}"
|
27 |
+
k = j + random.randint(-1,1)
|
28 |
+
poem_image = dataset[k]['image']
|
29 |
+
return poem_image,poem
|
30 |
+
|
31 |
+
def change_pic():
|
32 |
+
global k
|
33 |
+
rand_shift = random.choice([i for i in [-1,0,1] if i != k-j])
|
34 |
+
k = j + rand_shift
|
35 |
+
return dataset[k]['image']
|
36 |
+
|
37 |
+
with demo:
|
38 |
+
demo_title = gr.HTML('<h1 align="center">εθ―欣θ΅</h1>')
|
39 |
+
with gr.Row():
|
40 |
+
img = gr.Image(poem_image,scale=2)
|
41 |
+
poem_textbox = gr.Text(poem,scale=1,label="εθ―",show_copy_button=True)
|
42 |
+
with gr.Row():
|
43 |
+
btn1 = gr.Button('εζ’εθ―')
|
44 |
+
btn2 = gr.Button('εζ’ζεΎ')
|
45 |
+
btn1.click(random_poem,inputs=[],outputs=[img,poem_textbox])
|
46 |
+
btn2.click(change_pic,inputs=[],outputs=img)
|
47 |
+
demo.launch()
|