Firoj112 commited on
Commit
45ca866
·
verified ·
1 Parent(s): 405d426

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -168,7 +168,7 @@ def run_agent_chat(user_input: str, history: list):
168
  url = user_input.split()[0] if user_input.startswith("http") else next((w for w in user_input.split() if w.startswith("http")), "")
169
  request = user_input.replace(url, "").strip() or "Navigate to the URL and describe the page."
170
  else:
171
- url = "https://example.com"
172
  request = user_input
173
 
174
  search_request = f"Please go to {url}. {request}"
@@ -195,12 +195,6 @@ def run_agent_chat(user_input: str, history: list):
195
  except Exception as e:
196
  logger.error(f"Agent execution failed: {str(e)}")
197
  return f"Error: {str(e)}", None
198
- finally:
199
- try:
200
- driver.quit()
201
- logger.info("Chrome driver closed.")
202
- except:
203
- logger.warning("Failed to close Chrome driver.")
204
 
205
  # Custom Gradio interface
206
  def process_input(user_input, history):
@@ -214,9 +208,13 @@ if __name__ == "__main__":
214
  with gr.Blocks() as demo:
215
  gr.Markdown("# Web Navigation Agent")
216
  chatbot = gr.Chatbot(label="Chat")
217
- msg = gr.Textbox(placeholder="Enter URL and request (e.g., https://github.com/trending Click on Developers)")
218
  btn = gr.Button("Send")
219
  image = gr.Image(label="Latest Screenshot")
220
  btn.click(process_input, inputs=[msg, chatbot], outputs=[chatbot, image])
221
  msg.submit(process_input, inputs=[msg, chatbot], outputs=[chatbot, image])
222
- demo.launch()
 
 
 
 
 
168
  url = user_input.split()[0] if user_input.startswith("http") else next((w for w in user_input.split() if w.startswith("http")), "")
169
  request = user_input.replace(url, "").strip() or "Navigate to the URL and describe the page."
170
  else:
171
+ url = "[invalid url, do not cite]
172
  request = user_input
173
 
174
  search_request = f"Please go to {url}. {request}"
 
195
  except Exception as e:
196
  logger.error(f"Agent execution failed: {str(e)}")
197
  return f"Error: {str(e)}", None
 
 
 
 
 
 
198
 
199
  # Custom Gradio interface
200
  def process_input(user_input, history):
 
208
  with gr.Blocks() as demo:
209
  gr.Markdown("# Web Navigation Agent")
210
  chatbot = gr.Chatbot(label="Chat")
211
+ msg = gr.Textbox(placeholder="Enter URL and request (e.g., [invalid url, do not cite] Click on Developers)")
212
  btn = gr.Button("Send")
213
  image = gr.Image(label="Latest Screenshot")
214
  btn.click(process_input, inputs=[msg, chatbot], outputs=[chatbot, image])
215
  msg.submit(process_input, inputs=[msg, chatbot], outputs=[chatbot, image])
216
+ try:
217
+ demo.launch()
218
+ except KeyboardInterrupt:
219
+ driver.quit()
220
+ logger.info("Chrome driver closed on exit.")