Nikhil0987 commited on
Commit
8fb280f
Β·
verified Β·
1 Parent(s): f45b317

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -28
app.py CHANGED
@@ -83,47 +83,56 @@ def render_first(pdf_file):
83
  return image
84
 
85
  # Streamlit & Gradio Interface
 
 
86
  st.title("PDF-Powered Chatbot")
87
 
88
- with st.container():
89
- gr.Markdown("""
90
- <style>
91
- .image-container { height: 680px; }
92
- </style>
93
  """)
94
 
95
- with gr.Blocks() as demo: # Introduce a Blocks context
96
- with gr.Row():
97
- enable_box = gr.Textbox(placeholder='Enter OpenAI API key',
98
- show_label=False, interactive=True)
99
- disable_box = gr.Textbox(value='OpenAI API key is Set', interactive=False)
100
  change_api_key = gr.Button('Change Key')
101
 
102
- with gr.Row():
103
- chatbot = gr.Chatbot(value=[], elem_id='chatbot')
104
- show_img = gr.Image(label='Upload PDF')
105
- pdf_upload = gr.UploadButton("πŸ“ Upload a PDF", file_types=[".pdf"])
 
 
 
 
 
 
 
 
106
 
107
- # Event handlers within the Blocks context
108
- enable_box.submit(fn=set_apikey, inputs=[enable_box], outputs=[disable_box])
109
- change_api_key.click(fn=enable_api_box, outputs=[enable_box])
110
- pdf_upload.upload(fn=render_first, inputs=[pdf_upload], outputs=[show_img])
111
 
112
- txt = gr.Textbox(label="Enter your query", placeholder="Ask a question...")
113
  submit_btn = gr.Button('Submit')
114
 
115
- submit_btn.click(
116
- fn=add_text, inputs=[chatbot, txt], outputs=[chatbot], queue=False
117
- ).success(
118
- fn=generate_response, inputs=[chatbot, txt, pdf_upload], outputs=[chatbot, txt]
119
- ).success(
120
- fn=render_file, inputs=[pdf_upload], outputs=[show_img]
 
121
  )
122
 
123
  if __name__ == "__main__":
124
- gr.Interface(
125
  [render_first, add_text, generate_response, render_file],
126
- [pdf_upload1, chatbot, txt, pdf_upload2, pdf_upload3], # Unique names!
127
  [show_img, chatbot, txt, show_img],
128
- title="PDF-Powered Chatbot",
129
  ).launch()
 
83
  return image
84
 
85
  # Streamlit & Gradio Interface
86
+
87
+
88
  st.title("PDF-Powered Chatbot")
89
 
90
+ with st.container():
91
+ gr.Markdown("""
92
+ <style>
93
+ .image-container { height: 680px; }
94
+ </style>
95
  """)
96
 
97
+ with gr.Blocks() as demo: # Introduce a Blocks context
98
+ with gr.Row():
99
+ enable_box = gr.Textbox(placeholder='Enter OpenAI API key',
100
+ show_label=False, interactive=True)
101
+ disable_box = gr.Textbox(value='OpenAI API key is Set', interactive=False)
102
  change_api_key = gr.Button('Change Key')
103
 
104
+ with gr.Row():
105
+ chatbot = gr.Chatbot(value=[], elem_id='chatbot')
106
+ show_img = gr.Image(label='Upload PDF')
107
+
108
+ # Create multiple PDF upload buttons
109
+ pdf_upload1 = gr.UploadButton("πŸ“ Upload PDF 1", file_types=[".pdf"])
110
+ pdf_upload2 = gr.UploadButton("πŸ“ Upload PDF 2", file_types=[".pdf"])
111
+ pdf_upload3 = gr.UploadButton("πŸ“ Upload PDF 3", file_types=[".pdf"])
112
+
113
+ # Event handlers (adjust how you use the uploads in these functions)
114
+ enable_box.submit(fn=set_apikey, inputs=[enable_box], outputs=[disable_box])
115
+ change_api_key.click(fn=enable_api_box, outputs=[enable_box])
116
 
117
+ # Assuming you want to process the first PDF initially
118
+ pdf_upload1.upload(fn=render_first, inputs=[pdf_upload1], outputs=[show_img])
 
 
119
 
120
+ txt = gr.Textbox(label="Enter your query", placeholder="Ask a question...")
121
  submit_btn = gr.Button('Submit')
122
 
123
+ submit_btn.click(
124
+ fn=add_text, inputs=[chatbot, txt], outputs=[chatbot], queue=False
125
+ ).success(
126
+ # How do you want to use the different uploads here?
127
+ fn=generate_response, inputs=[chatbot, txt, pdf_upload1], outputs=[chatbot, txt]
128
+ ).success(
129
+ fn=render_file, inputs=[pdf_upload1], outputs=[show_img]
130
  )
131
 
132
  if __name__ == "__main__":
133
+ gr.Interface(
134
  [render_first, add_text, generate_response, render_file],
135
+ [pdf_upload1, chatbot, txt, pdf_upload2, pdf_upload3],
136
  [show_img, chatbot, txt, show_img],
137
+ title="PDF-Powered Chatbot"
138
  ).launch()