Didier commited on
Commit
a1a3bba
·
verified ·
1 Parent(s): 91ff6bf

Upon loading the page, start the indexing of the default PDF file. Add a clear button.

Browse files
Files changed (1) hide show
  1. app.py +17 -2
app.py CHANGED
@@ -74,6 +74,11 @@ def generate_response(question: str) -> list[str, str, str]:
74
  return responses, references, snippets
75
 
76
 
 
 
 
 
 
77
  with gr.Blocks() as demo:
78
  gr.Markdown("""
79
  # Retrieval (ColBERT) + Generation (DSPy & Mistral)
@@ -97,7 +102,7 @@ with gr.Blocks() as demo:
97
  # Question to answer
98
  question = gr.Textbox(
99
  label="Question",
100
- placeholder="What is dividend stripping?"
101
  )
102
  response = gr.Textbox(
103
  label="Response",
@@ -108,7 +113,9 @@ with gr.Blocks() as demo:
108
  snippets = gr.HTML(label="Snippets")
109
 
110
  # button
111
- response_button = gr.Button("Submit", variant='primary')
 
 
112
 
113
  # Example questions given default provided PDF file
114
  with gr.Accordion("Sample questions", open=False):
@@ -154,6 +161,14 @@ with gr.Blocks() as demo:
154
  inputs=[question],
155
  outputs=[response, references, snippets]
156
  )
 
 
 
 
 
 
 
 
157
 
158
 
159
  demo.launch(show_api=False)
 
74
  return responses, references, snippets
75
 
76
 
77
+ def on_load_build():
78
+ pdf_files = ["OECD_Dividend_tax_fraud_2023-en.pdf",]
79
+ return build_rag_model(pdf_files)
80
+
81
+
82
  with gr.Blocks() as demo:
83
  gr.Markdown("""
84
  # Retrieval (ColBERT) + Generation (DSPy & Mistral)
 
102
  # Question to answer
103
  question = gr.Textbox(
104
  label="Question",
105
+ placeholder=""
106
  )
107
  response = gr.Textbox(
108
  label="Response",
 
113
  snippets = gr.HTML(label="Snippets")
114
 
115
  # button
116
+ with gr.Row():
117
+ response_button = gr.Button("Submit", variant='primary')
118
+ clear_question_button = gr.Button("Clear", variant='secondary')
119
 
120
  # Example questions given default provided PDF file
121
  with gr.Accordion("Sample questions", open=False):
 
161
  inputs=[question],
162
  outputs=[response, references, snippets]
163
  )
164
+ clear_question_button.click(
165
+ fn=lambda: ('', '', '', ''),
166
+ inputs=[],
167
+ outputs=[question, response, references, snippets]
168
+ )
169
+
170
+ # Upon loading, index a default PDF file
171
+ demo.load(on_load_build, outputs=[build_status])
172
 
173
 
174
  demo.launch(show_api=False)