Spaces:
Sleeping
Sleeping
Commit
Β·
f1be909
1
Parent(s):
bd9d9d5
Refactor code for improved UI layout and readability
Browse files
app.py
CHANGED
@@ -125,7 +125,7 @@ def generate_blurb(prompt):
|
|
125 |
|
126 |
# Modified function to log blurb and vote
|
127 |
def log_blurb_and_vote(
|
128 |
-
prompt, blurb, vote, user_info: gr.OAuthProfile | None, has_voted
|
129 |
):
|
130 |
if has_voted:
|
131 |
return (
|
@@ -150,9 +150,6 @@ def log_blurb_and_vote(
|
|
150 |
return f"Logged: {vote} by user {user_id}", True, gr.Row.update(visible=False)
|
151 |
|
152 |
|
153 |
-
# Create custom theme
|
154 |
-
tufte_theme = TufteInspired()
|
155 |
-
|
156 |
# Create Gradio interface
|
157 |
with gr.Blocks(theme=tufte_theme) as demo:
|
158 |
gr.Markdown("<h1 style='text-align: center;'>Would you read this book?</h1>")
|
@@ -161,7 +158,6 @@ with gr.Blocks(theme=tufte_theme) as demo:
|
|
161 |
Would you read a book based on this LLM generated blurb? <br> Your vote will be added to <a href="https://huggingface.co/datasets/your-username/your-dataset-repo">this</a> Hugging Face dataset</p>"""
|
162 |
)
|
163 |
|
164 |
-
# Add the login button
|
165 |
login_btn = gr.LoginButton()
|
166 |
|
167 |
with gr.Row():
|
@@ -171,26 +167,26 @@ with gr.Blocks(theme=tufte_theme) as demo:
|
|
171 |
blurb_output = gr.Markdown(label="Book blurb")
|
172 |
has_voted = gr.State(False)
|
173 |
|
174 |
-
with gr.Row(
|
175 |
upvote_btn = gr.Button("π would read")
|
176 |
downvote_btn = gr.Button("π wouldn't read")
|
177 |
|
178 |
vote_output = gr.Textbox(label="Vote Status", interactive=False, visible=False)
|
179 |
|
180 |
def generate_and_show(prompt):
|
181 |
-
return "Generating...", gr.Row.update(visible=False)
|
182 |
|
183 |
def show_voting_buttons(blurb):
|
184 |
-
return blurb, gr.Row.update(visible=True)
|
185 |
|
186 |
generate_btn.click(get_and_store_prompt, outputs=prompt_state).then(
|
187 |
generate_and_show,
|
188 |
inputs=prompt_state,
|
189 |
-
outputs=[blurb_output,
|
190 |
).then(generate_blurb, inputs=prompt_state, outputs=blurb_output).then(
|
191 |
show_voting_buttons,
|
192 |
inputs=blurb_output,
|
193 |
-
outputs=[blurb_output,
|
194 |
)
|
195 |
|
196 |
upvote_btn.click(
|
|
|
125 |
|
126 |
# Modified function to log blurb and vote
|
127 |
def log_blurb_and_vote(
|
128 |
+
prompt, blurb, vote, user_info: gr.OAuthProfile | None, has_voted
|
129 |
):
|
130 |
if has_voted:
|
131 |
return (
|
|
|
150 |
return f"Logged: {vote} by user {user_id}", True, gr.Row.update(visible=False)
|
151 |
|
152 |
|
|
|
|
|
|
|
153 |
# Create Gradio interface
|
154 |
with gr.Blocks(theme=tufte_theme) as demo:
|
155 |
gr.Markdown("<h1 style='text-align: center;'>Would you read this book?</h1>")
|
|
|
158 |
Would you read a book based on this LLM generated blurb? <br> Your vote will be added to <a href="https://huggingface.co/datasets/your-username/your-dataset-repo">this</a> Hugging Face dataset</p>"""
|
159 |
)
|
160 |
|
|
|
161 |
login_btn = gr.LoginButton()
|
162 |
|
163 |
with gr.Row():
|
|
|
167 |
blurb_output = gr.Markdown(label="Book blurb")
|
168 |
has_voted = gr.State(False)
|
169 |
|
170 |
+
with gr.Row() as voting_row:
|
171 |
upvote_btn = gr.Button("π would read")
|
172 |
downvote_btn = gr.Button("π wouldn't read")
|
173 |
|
174 |
vote_output = gr.Textbox(label="Vote Status", interactive=False, visible=False)
|
175 |
|
176 |
def generate_and_show(prompt):
|
177 |
+
return "Generating...", False, gr.Row.update(visible=False)
|
178 |
|
179 |
def show_voting_buttons(blurb):
|
180 |
+
return blurb, False, gr.Row.update(visible=True)
|
181 |
|
182 |
generate_btn.click(get_and_store_prompt, outputs=prompt_state).then(
|
183 |
generate_and_show,
|
184 |
inputs=prompt_state,
|
185 |
+
outputs=[blurb_output, has_voted, voting_row],
|
186 |
).then(generate_blurb, inputs=prompt_state, outputs=blurb_output).then(
|
187 |
show_voting_buttons,
|
188 |
inputs=blurb_output,
|
189 |
+
outputs=[blurb_output, has_voted, voting_row],
|
190 |
)
|
191 |
|
192 |
upvote_btn.click(
|