Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -148,7 +148,7 @@ def demo():
|
|
148 |
collection_name = gr.State()
|
149 |
|
150 |
gr.Markdown(
|
151 |
-
"""<center><h2>
|
152 |
<h3>Ask any questions about your PDF documents</h3>""")
|
153 |
gr.Markdown(
|
154 |
"""<b>Note:</b> This AI assistant, using Langchain and open-source LLMs, performs retrieval-augmented generation (RAG) from your PDF documents. \
|
@@ -157,50 +157,50 @@ def demo():
|
|
157 |
<br><b>Warning:</b> This space uses the free CPU Basic hardware from Hugging Face. Some steps and LLM models used below (free inference endpoints) can take some time to generate a reply.
|
158 |
""")
|
159 |
|
160 |
-
gr.
|
161 |
-
with gr.Row():
|
162 |
-
slider_chunk_size = gr.Slider(minimum=100, maximum=1000, value=600, step=20, label="Chunk size",
|
163 |
-
info="Chunk size", interactive=True)
|
164 |
-
with gr.Row():
|
165 |
-
slider_chunk_overlap = gr.Slider(minimum=10, maximum=200, value=40, step=10, label="Chunk overlap",
|
166 |
-
info="Chunk overlap", interactive=True)
|
167 |
-
with gr.Row():
|
168 |
-
db_progress = gr.Textbox(label="Vector database initialization", value="None")
|
169 |
-
with gr.Row():
|
170 |
-
db_btn = gr.Button("Generate vector database")
|
171 |
-
|
172 |
-
gr.Markdown("<h4>Step 2 - Initialize QA chain</h4>")
|
173 |
-
with gr.Row():
|
174 |
-
slider_temperature = gr.Slider(minimum=0.01, maximum=1.0, value=0.7, step=0.1, label="Temperature",
|
175 |
-
info="Model temperature", interactive=True)
|
176 |
-
with gr.Row():
|
177 |
-
slider_maxtokens = gr.Slider(minimum=224, maximum=4096, value=1024, step=32, label="Max Tokens",
|
178 |
-
info="Model max tokens", interactive=True)
|
179 |
-
with gr.Row():
|
180 |
-
slider_topk = gr.Slider(minimum=1, maximum=10, value=3, step=1, label="top-k samples",
|
181 |
-
info="Model top-k samples", interactive=True)
|
182 |
-
with gr.Row():
|
183 |
-
llm_progress = gr.Textbox(value="None", label="QA chain initialization")
|
184 |
-
with gr.Row():
|
185 |
-
qachain_btn = gr.Button("Initialize Question Answering chain")
|
186 |
-
|
187 |
-
gr.Markdown("<h4>Step 3 - Chatbot</h4>")
|
188 |
-
chatbot = gr.Chatbot(height=300)
|
189 |
-
with gr.Accordion("Advanced - Document references", open=False):
|
190 |
with gr.Row():
|
191 |
-
|
192 |
-
|
193 |
with gr.Row():
|
194 |
-
|
195 |
-
|
196 |
with gr.Row():
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
with gr.
|
202 |
-
|
203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
|
205 |
db_btn.click(initialize_database, \
|
206 |
inputs=[slider_chunk_size, slider_chunk_overlap], \
|
|
|
148 |
collection_name = gr.State()
|
149 |
|
150 |
gr.Markdown(
|
151 |
+
"""<center><h2>Haor Chatbot by Tasrif Nur Himel</center></h2>
|
152 |
<h3>Ask any questions about your PDF documents</h3>""")
|
153 |
gr.Markdown(
|
154 |
"""<b>Note:</b> This AI assistant, using Langchain and open-source LLMs, performs retrieval-augmented generation (RAG) from your PDF documents. \
|
|
|
157 |
<br><b>Warning:</b> This space uses the free CPU Basic hardware from Hugging Face. Some steps and LLM models used below (free inference endpoints) can take some time to generate a reply.
|
158 |
""")
|
159 |
|
160 |
+
with gr.Tab("Step 1 - Process and Load Document"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
with gr.Row():
|
162 |
+
slider_chunk_size = gr.Slider(minimum=100, maximum=1000, value=600, step=20, label="Chunk size",
|
163 |
+
info="Chunk size", interactive=True)
|
164 |
with gr.Row():
|
165 |
+
slider_chunk_overlap = gr.Slider(minimum=10, maximum=200, value=40, step=10, label="Chunk overlap",
|
166 |
+
info="Chunk overlap", interactive=True)
|
167 |
with gr.Row():
|
168 |
+
db_progress = gr.Textbox(label="Vector database initialization", value="None")
|
169 |
+
with gr.Row():
|
170 |
+
db_btn = gr.Button("Generate vector database")
|
171 |
+
|
172 |
+
with gr.Tab("Step 2 - Initialize QA chain"):
|
173 |
+
with gr.Row():
|
174 |
+
slider_temperature = gr.Slider(minimum=0.01, maximum=1.0, value=0.7, step=0.1, label="Temperature",
|
175 |
+
info="Model temperature", interactive=True)
|
176 |
+
with gr.Row():
|
177 |
+
slider_maxtokens = gr.Slider(minimum=224, maximum=4096, value=1024, step=32, label="Max Tokens",
|
178 |
+
info="Model max tokens", interactive=True)
|
179 |
+
with gr.Row():
|
180 |
+
slider_topk = gr.Slider(minimum=1, maximum=10, value=3, step=1, label="top-k samples",
|
181 |
+
info="Model top-k samples", interactive=True)
|
182 |
+
with gr.Row():
|
183 |
+
llm_progress = gr.Textbox(value="None", label="QA chain initialization")
|
184 |
+
with gr.Row():
|
185 |
+
qachain_btn = gr.Button("Initialize Question Answering chain")
|
186 |
+
|
187 |
+
with gr.Tab("Step 3 - Chatbot"):
|
188 |
+
chatbot = gr.Chatbot(height=300)
|
189 |
+
with gr.Accordion("Advanced - Document references", open=False):
|
190 |
+
with gr.Row():
|
191 |
+
doc_source1 = gr.Textbox(label="Reference 1", lines=2, container=True, scale=20)
|
192 |
+
source1_page = gr.Number(label="Page", scale=1)
|
193 |
+
with gr.Row():
|
194 |
+
doc_source2 = gr.Textbox(label="Reference 2", lines=2, container=True, scale=20)
|
195 |
+
source2_page = gr.Number(label="Page", scale=1)
|
196 |
+
with gr.Row():
|
197 |
+
doc_source3 = gr.Textbox(label="Reference 3", lines=2, container=True, scale=20)
|
198 |
+
source3_page = gr.Number(label="Page", scale=1)
|
199 |
+
with gr.Row():
|
200 |
+
msg = gr.Textbox(placeholder="Type message (e.g. 'What is this document about?')", container=True)
|
201 |
+
with gr.Row():
|
202 |
+
submit_btn = gr.Button("Submit message")
|
203 |
+
clear_btn = gr.ClearButton([msg, chatbot], value="Clear conversation")
|
204 |
|
205 |
db_btn.click(initialize_database, \
|
206 |
inputs=[slider_chunk_size, slider_chunk_overlap], \
|