theosaurus commited on
Commit
7f4392a
·
1 Parent(s): 5c12201

Refactored example update function

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -938,7 +938,7 @@ chat_interface = gr.ChatInterface(
938
  ],
939
  stop_btn=True,
940
  examples=[
941
- [f"In bullet-points, give me the classes from that Turtle ontology :"]
942
  ],
943
  cache_examples=False,
944
  type="messages",
@@ -947,9 +947,17 @@ chat_interface = gr.ChatInterface(
947
  )
948
 
949
  with gr.Blocks() as demo:
950
- def set_example(file):
951
- gr_file = gr.File(value=file, visible=True)
952
- chat_interface.examples.__setitem__(slice(None), [[gr_file]])
 
 
 
 
 
 
 
 
953
  return gr_file
954
 
955
  with gr.Row():
@@ -962,7 +970,7 @@ with gr.Blocks() as demo:
962
  )
963
  # use the file content as an example for the chat interface
964
  txt_file.change(
965
- fn=set_example,
966
  inputs=txt_file,
967
  outputs=gr.File(visible=False)
968
  )
 
938
  ],
939
  stop_btn=True,
940
  examples=[
941
+ ["In bullet-points, give me the classes from that Turtle ontology :"]
942
  ],
943
  cache_examples=False,
944
  type="messages",
 
947
  )
948
 
949
  with gr.Blocks() as demo:
950
+ def update_examples(file_path):
951
+ if file_path is None:
952
+ return None
953
+ gr_file = gr.File(value=file_path, visible=True)
954
+ new_examples = [[f"Analyze the following document: {file_path}"]]
955
+
956
+ chat_interface.examples = new_examples
957
+ chat_interface.examples_messages = chat_interface._setup_example_messages(examples=new_examples,
958
+ example_icons=None,
959
+ example_labels=None)
960
+
961
  return gr_file
962
 
963
  with gr.Row():
 
970
  )
971
  # use the file content as an example for the chat interface
972
  txt_file.change(
973
+ fn=update_examples,
974
  inputs=txt_file,
975
  outputs=gr.File(visible=False)
976
  )