Nikhil0987 commited on
Commit
4f34423
Β·
verified Β·
1 Parent(s): fc5882b

Update app.py

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