hanzla commited on
Commit
7adf0ef
·
1 Parent(s): ae4a10a
Files changed (1) hide show
  1. src/interface.py +18 -14
src/interface.py CHANGED
@@ -1,12 +1,17 @@
1
  import gradio as gr
2
 
3
-
4
  def create_demo():
5
- def on_upload(file, slider):
6
- # Disable the slider when a file is uploaded
7
- return gr.update(disabled=True), "PDF uploaded!"
8
-
9
- with gr.Blocks(title="RAG Chatbot Q&A", theme="Soft") as demo:
 
 
 
 
 
10
  with gr.Column():
11
  with gr.Row():
12
  chat_history = gr.Chatbot(value=[], elem_id='chatbot', height=680)
@@ -14,22 +19,21 @@ def create_demo():
14
 
15
  with gr.Row():
16
  with gr.Column(): # Adjust scale as needed
17
- slider1 = gr.Slider(minimum=256, maximum=1024, value=256, label="Chunk Size")
18
-
19
  with gr.Row():
20
  with gr.Column(scale=0.60):
21
- text_input = gr.Textbox(show_label=False, placeholder="Type here to ask your PDF", container=False)
 
 
 
22
  with gr.Column(scale=0.20):
23
  submit_button = gr.Button('Send')
24
  with gr.Column(scale=0.20):
25
- uploaded_pdf = gr.UploadButton("📁 Upload PDF", file_types=[".pdf"])
26
-
27
- # Linking the upload button to the slider update
28
- uploaded_pdf.change(on_upload, inputs=[uploaded_pdf], outputs=[slider1])
29
 
30
  return demo, chat_history, show_img, text_input, submit_button, uploaded_pdf, slider1
31
 
32
-
33
  if __name__ == '__main__':
34
  demo, chatbot, show_img, text_input, submit_button, uploaded_pdf, slider1 = create_demo()
 
35
  demo.launch()
 
1
  import gradio as gr
2
 
3
+ # Gradio application setup
4
  def create_demo():
5
+ # JavaScript to disable the slider after the upload button is pressed
6
+ javascript = """
7
+ document.querySelector('input[type=file]').addEventListener('change', function() {
8
+ if (this.files.length > 0) {
9
+ document.getElementById('slider1').setAttribute('disabled', true);
10
+ }
11
+ });
12
+ """
13
+
14
+ with gr.Blocks(title="RAG Chatbot Q&A", theme="Soft", js=javascript) as demo:
15
  with gr.Column():
16
  with gr.Row():
17
  chat_history = gr.Chatbot(value=[], elem_id='chatbot', height=680)
 
19
 
20
  with gr.Row():
21
  with gr.Column(): # Adjust scale as needed
22
+ slider1 = gr.Slider(minimum=256, maximum=1024, value=256, label="Chunk Size", elem_id='slider1')
 
23
  with gr.Row():
24
  with gr.Column(scale=0.60):
25
+ text_input = gr.Textbox(
26
+ show_label=False,
27
+ placeholder="Type here to ask your PDF",
28
+ container=False)
29
  with gr.Column(scale=0.20):
30
  submit_button = gr.Button('Send')
31
  with gr.Column(scale=0.20):
32
+ uploaded_pdf = gr.UploadButton("📁 Upload PDF", file_types=[".pdf"], elem_id='upload_pdf')
 
 
 
33
 
34
  return demo, chat_history, show_img, text_input, submit_button, uploaded_pdf, slider1
35
 
 
36
  if __name__ == '__main__':
37
  demo, chatbot, show_img, text_input, submit_button, uploaded_pdf, slider1 = create_demo()
38
+ demo.queue()
39
  demo.launch()