Nikhil0987 commited on
Commit
eeae138
Β·
verified Β·
1 Parent(s): ccfb409

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -26
app.py CHANGED
@@ -91,32 +91,34 @@ with st.container():
91
  .image-container { height: 680px; }
92
  </style>
93
  """)
94
- with gr.Row():
95
- enable_box = gr.Textbox(placeholder='Enter OpenAI API key',
96
- show_label=False, interactive=True)
97
- disable_box = gr.Textbox(value='OpenAI API key is Set', interactive=False)
98
- change_api_key = gr.Button('Change Key')
99
-
100
- with gr.Row():
101
- chatbot = gr.Chatbot(value=[], elem_id='chatbot')
102
- show_img = gr.Image(label='Upload PDF')
103
- pdf_upload = gr.UploadButton("πŸ“ Upload a PDF", file_types=[".pdf"])
104
-
105
- # Event handlers
106
- enable_box.submit(fn=set_apikey, inputs=[enable_box], outputs=[disable_box])
107
- change_api_key.click(fn=enable_api_box, outputs=[enable_box])
108
- pdf_upload.upload(fn=render_first, inputs=[pdf_upload], outputs=[show_img])
109
-
110
- txt = gr.Textbox(label="Enter your query", placeholder="Ask a question...")
111
- submit_btn = gr.Button('Submit')
112
-
113
- submit_btn.click(
114
- fn=add_text, inputs=[chatbot, txt], outputs=[chatbot], queue=False
115
- ).success(
116
- fn=generate_response, inputs=[chatbot, txt, pdf_upload], outputs=[chatbot, txt]
117
- ).success(
118
- fn=render_file, inputs=[pdf_upload], outputs=[show_img]
119
- )
 
 
120
 
121
  if __name__ == "__main__":
122
  gr.Interface(
 
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(