Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gradio.themes.base import Base
|
3 |
+
from gradio.themes.utils import colors, fonts, sizes
|
4 |
+
|
5 |
+
class TufteInspired(Base):
|
6 |
+
def __init__(
|
7 |
+
self,
|
8 |
+
*,
|
9 |
+
primary_hue: colors.Color | str = colors.stone,
|
10 |
+
secondary_hue: colors.Color | str = colors.gray,
|
11 |
+
neutral_hue: colors.Color | str = colors.gray,
|
12 |
+
spacing_size: sizes.Size | str = sizes.spacing_md,
|
13 |
+
radius_size: sizes.Size | str = sizes.radius_sm,
|
14 |
+
text_size: sizes.Size | str = sizes.text_lg,
|
15 |
+
font: list[fonts.Font | str] = [
|
16 |
+
fonts.GoogleFont("EB Garamond"),
|
17 |
+
"Georgia",
|
18 |
+
"serif"
|
19 |
+
],
|
20 |
+
font_mono: list[fonts.Font | str] = [
|
21 |
+
fonts.GoogleFont("IBM Plex Mono"),
|
22 |
+
"Consolas",
|
23 |
+
"monospace"
|
24 |
+
],
|
25 |
+
):
|
26 |
+
super().__init__(
|
27 |
+
primary_hue=primary_hue,
|
28 |
+
secondary_hue=secondary_hue,
|
29 |
+
neutral_hue=neutral_hue,
|
30 |
+
spacing_size=spacing_size,
|
31 |
+
radius_size=radius_size,
|
32 |
+
text_size=text_size,
|
33 |
+
font=font,
|
34 |
+
font_mono=font_mono,
|
35 |
+
)
|
36 |
+
self.set(
|
37 |
+
body_background_fill="#fffff8",
|
38 |
+
body_background_fill_dark="#151515",
|
39 |
+
body_text_color="*neutral_950",
|
40 |
+
body_text_color_dark="*neutral_50",
|
41 |
+
background_fill_primary="#fffff8",
|
42 |
+
background_fill_primary_dark="#151515",
|
43 |
+
block_title_text_weight="400",
|
44 |
+
block_border_width="0px",
|
45 |
+
block_shadow="none",
|
46 |
+
button_primary_background_fill="*primary_100",
|
47 |
+
button_primary_background_fill_hover="*primary_200",
|
48 |
+
button_primary_text_color="*neutral_950",
|
49 |
+
button_primary_border_color="*primary_300",
|
50 |
+
button_shadow="none",
|
51 |
+
input_background_fill="*secondary_50",
|
52 |
+
input_background_fill_dark="*secondary_900",
|
53 |
+
input_border_color="*secondary_200",
|
54 |
+
input_border_color_dark="*secondary_700",
|
55 |
+
input_shadow="none",
|
56 |
+
)
|
57 |
+
|
58 |
+
import gradio as gr
|
59 |
+
import json
|
60 |
+
from datetime import datetime
|
61 |
+
|
62 |
+
# Placeholder LLM function
|
63 |
+
def generate_blurb():
|
64 |
+
# This is where you'd call your LLM model
|
65 |
+
return "A thrilling journey through time and space, where heroes rise and fall, and the fate of the universe hangs in the balance."
|
66 |
+
|
67 |
+
# Function to log blurb and vote
|
68 |
+
def log_blurb_and_vote(blurb, vote):
|
69 |
+
log_entry = {
|
70 |
+
"timestamp": datetime.now().isoformat(),
|
71 |
+
"blurb": blurb,
|
72 |
+
"vote": vote
|
73 |
+
}
|
74 |
+
with open("blurb_log.jsonl", "a") as f:
|
75 |
+
f.write(json.dumps(log_entry) + "\n")
|
76 |
+
return f"Logged: {vote}"
|
77 |
+
|
78 |
+
# Create custom theme
|
79 |
+
tufte_theme = TufteInspired()
|
80 |
+
|
81 |
+
# Create Gradio interface
|
82 |
+
with gr.Blocks(theme=tufte_theme) as demo:
|
83 |
+
gr.Markdown("<h1 style='text-align: center;'>Would you read it?</h1>")
|
84 |
+
gr.Markdown("Click the button to generate a blurb for a made-up book, then vote on its quality.")
|
85 |
+
|
86 |
+
with gr.Row():
|
87 |
+
generate_btn = gr.Button("Write a Blurb", variant="primary")
|
88 |
+
|
89 |
+
blurb_output = gr.Textbox(label="Generated Blurb", lines=5, interactive=False)
|
90 |
+
|
91 |
+
with gr.Row():
|
92 |
+
upvote_btn = gr.Button("π would read")
|
93 |
+
downvote_btn = gr.Button("π wouldn't read")
|
94 |
+
|
95 |
+
vote_output = gr.Textbox(label="Vote Status", interactive=False)
|
96 |
+
|
97 |
+
generate_btn.click(generate_blurb, outputs=blurb_output)
|
98 |
+
upvote_btn.click(lambda x: log_blurb_and_vote(x, "upvote"), inputs=blurb_output, outputs=vote_output)
|
99 |
+
downvote_btn.click(lambda x: log_blurb_and_vote(x, "downvote"), inputs=blurb_output, outputs=vote_output)
|
100 |
+
|
101 |
+
if __name__ == "__main__":
|
102 |
+
demo.launch()
|