Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
-
from smolagents import CodeAgent, LiteLLMModel, tool
|
4 |
from smolagents.agents import ActionStep
|
5 |
import helium
|
6 |
from selenium import webdriver
|
@@ -99,7 +99,7 @@ def save_screenshot(memory_step: ActionStep, agent: CodeAgent) -> Image.Image:
|
|
99 |
# Save new screenshot
|
100 |
png_bytes = driver.get_screenshot_as_png()
|
101 |
image = Image.open(BytesIO(png_bytes))
|
102 |
-
screenshot_dir = os.path.join(tempfile.gettempdir(), "
|
103 |
os.makedirs(screenshot_dir, exist_ok=True)
|
104 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
105 |
screenshot_filename = f"screenshot_step_{current_step}_{timestamp}.png"
|
@@ -169,7 +169,7 @@ def run_agent_chat(user_input: str, history: list):
|
|
169 |
url = user_input.split()[0] if user_input.startswith("http") else next((w for w in user_input.split() if w.startswith("http")), "")
|
170 |
request = user_input.replace(url, "").strip() or "Navigate to the URL and describe the page."
|
171 |
else:
|
172 |
-
url = "https://example.com"
|
173 |
request = user_input
|
174 |
|
175 |
search_request = f"Please go to {url}. {request}"
|
@@ -198,8 +198,21 @@ def run_agent_chat(user_input: str, history: list):
|
|
198 |
except:
|
199 |
logger.warning("Failed to close Chrome driver.")
|
200 |
|
201 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
if __name__ == "__main__":
|
203 |
-
|
204 |
-
|
205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
+
from smolagents import CodeAgent, LiteLLMModel, tool
|
4 |
from smolagents.agents import ActionStep
|
5 |
import helium
|
6 |
from selenium import webdriver
|
|
|
99 |
# Save new screenshot
|
100 |
png_bytes = driver.get_screenshot_as_png()
|
101 |
image = Image.open(BytesIO(png_bytes))
|
102 |
+
screenshot_dir = os.path.join(tempfile.gettempdir(), "web_agent_screenshots")
|
103 |
os.makedirs(screenshot_dir, exist_ok=True)
|
104 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
105 |
screenshot_filename = f"screenshot_step_{current_step}_{timestamp}.png"
|
|
|
169 |
url = user_input.split()[0] if user_input.startswith("http") else next((w for w in user_input.split() if w.startswith("http")), "")
|
170 |
request = user_input.replace(url, "").strip() or "Navigate to the URL and describe the page."
|
171 |
else:
|
172 |
+
url = "https://example.com"
|
173 |
request = user_input
|
174 |
|
175 |
search_request = f"Please go to {url}. {request}"
|
|
|
198 |
except:
|
199 |
logger.warning("Failed to close Chrome driver.")
|
200 |
|
201 |
+
# Custom Gradio interface
|
202 |
+
def process_input(user_input, history):
|
203 |
+
if not user_input.strip():
|
204 |
+
return history, None
|
205 |
+
output, latest_screenshot = run_agent_chat(user_input, history)
|
206 |
+
new_history = history + [[user_input, output]]
|
207 |
+
return new_history, latest_screenshot
|
208 |
+
|
209 |
if __name__ == "__main__":
|
210 |
+
with gr.Blocks() as demo:
|
211 |
+
gr.Markdown("# Web Navigation Agent")
|
212 |
+
chatbot = gr.Chatbot(label="Chat")
|
213 |
+
msg = gr.Textbox(placeholder="Enter URL and request (e.g., https://github.com/trending Click on Developers)")
|
214 |
+
btn = gr.Button("Send")
|
215 |
+
image = gr.Image(label="Latest Screenshot")
|
216 |
+
btn.click(process_input, inputs=[msg, chatbot], outputs=[chatbot, image])
|
217 |
+
msg.submit(process_input, inputs=[msg, chatbot], outputs=[chatbot, image])
|
218 |
+
demo.launch()
|