wenkai commited on
Commit
d638ffc
Β·
verified Β·
1 Parent(s): ecce336

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -16
app.py CHANGED
@@ -203,15 +203,21 @@ def save_feedback(inputs):
203
  return "Thanks your advice!"
204
 
205
 
206
- def yes(message, history):
207
- return "yes"
 
 
208
 
 
 
 
 
 
209
 
210
- def vote(data: gr.LikeData):
211
- if data.liked:
212
- print("You upvoted this prediction: " + data.value["value"])
213
- else:
214
- print("You downvoted this prediction: " + data.value["value"])
215
 
216
 
217
  # Define the FAPM interface
@@ -242,6 +248,7 @@ css = """
242
 
243
  with gr.Blocks(css=css) as demo:
244
  gr.Markdown(description)
 
245
  with gr.Tab(label="Protein caption"):
246
  with gr.Row():
247
  with gr.Column():
@@ -252,14 +259,13 @@ with gr.Blocks(css=css) as demo:
252
  # output_text = gr.Textbox(label="Output Text")
253
  with gr.Accordion('Prediction:', open=True):
254
  output_markdown = gr.Markdown(label="Output")
255
- with gr.Row():
256
- chatbot = gr.Chatbot(placeholder="<strong>Is this prediction helpful?</strong><br>")
257
- chatbot.like(vote, None, None)
258
- # with gr.Row(label="Your feedback"):
259
- # with gr.Column():
260
- # inputs = gr.Textbox(type="text")
261
- # output_markdown = gr.Markdown(label="Output")
262
- # feedback_btn = gr.Button(value="Submit")
263
  # O14813 train index 127, 266, 738, 1060 test index 4
264
  gr.Examples(
265
  examples=[
@@ -277,7 +283,9 @@ with gr.Blocks(css=css) as demo:
277
  label='Try examples'
278
  )
279
  submit_btn.click(generate_caption, [input_protein, prompt], [output_markdown])
280
- # feedback_btn.click(save_feedback, [inputs], [output_markdown])
 
 
281
 
282
  demo.launch(debug=True)
283
 
 
203
  return "Thanks your advice!"
204
 
205
 
206
+ feedback_data = []
207
+ def chatbot_respond(message, history=[]):
208
+ response = "yes"
209
+ return response, history + [(message, response)]
210
 
211
+ # Functions to handle like/dislike
212
+ def upvote(vote_id):
213
+ feedback_data.append((vote_id, "upvote"))
214
+ print(f"Current feedback data: {feedback_data}")
215
+ return "You liked this response"
216
 
217
+ def downvote(vote_id):
218
+ feedback_data.append((vote_id, "downvote"))
219
+ print(f"Current feedback data: {feedback_data}")
220
+ return "You disliked this response"
 
221
 
222
 
223
  # Define the FAPM interface
 
248
 
249
  with gr.Blocks(css=css) as demo:
250
  gr.Markdown(description)
251
+ vote_id = gr.State(0)
252
  with gr.Tab(label="Protein caption"):
253
  with gr.Row():
254
  with gr.Column():
 
259
  # output_text = gr.Textbox(label="Output Text")
260
  with gr.Accordion('Prediction:', open=True):
261
  output_markdown = gr.Markdown(label="Output")
262
+ upvote_button = gr.Button("πŸ‘")
263
+ downvote_button = gr.Button("πŸ‘Ž")
264
+
265
+ with gr.Column():
266
+ inputs = gr.Textbox(type="text")
267
+ feedback_markdown = gr.Markdown(label="Output")
268
+ feedback_btn = gr.Button(value="Submit")
 
269
  # O14813 train index 127, 266, 738, 1060 test index 4
270
  gr.Examples(
271
  examples=[
 
283
  label='Try examples'
284
  )
285
  submit_btn.click(generate_caption, [input_protein, prompt], [output_markdown])
286
+ upvote_button.click(upvote, vote_id, None)
287
+ downvote_button.click(downvote, vote_id, None)
288
+ feedback_btn.click(save_feedback, [inputs], [feedback_markdown])
289
 
290
  demo.launch(debug=True)
291