Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,20 +4,81 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def my_custom_tool(arg1:str, arg2:
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
"""A tool that does nothing yet
|
| 15 |
Args:
|
| 16 |
arg1: the first argument
|
| 17 |
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
return "What magic will you build ?"
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
from selenium.webdriver.common.by import By
|
| 8 |
+
from selenium.webdriver.common.keys import Keys
|
| 9 |
+
import time
|
| 10 |
|
| 11 |
from Gradio_UI import GradioUI
|
| 12 |
|
| 13 |
+
# Set credentials (replace with actual details)
|
| 14 |
+
USERNAME = "pradeepp@rocketmail.com"
|
| 15 |
+
PASSWORD = "Y2ktest1"
|
| 16 |
+
|
| 17 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 18 |
@tool
|
| 19 |
+
def my_custom_tool(arg1:str, arg2:str)-> str: #it's import to specify the return type
|
| 20 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 21 |
"""A tool that does nothing yet
|
| 22 |
Args:
|
| 23 |
arg1: the first argument
|
| 24 |
arg2: the second argument
|
| 25 |
"""
|
|
|
|
| 26 |
|
| 27 |
+
# Define the agent
|
| 28 |
+
agent = SmolAgent(
|
| 29 |
+
browser="chrome", # Uses Chrome WebDriver
|
| 30 |
+
headless=False, # Set to True to run in background
|
| 31 |
+
maximize=True,
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
try:
|
| 35 |
+
# Step 1: Open Substack Login Page
|
| 36 |
+
agent.goto("https://tensorhealth.substack.com/")
|
| 37 |
+
|
| 38 |
+
# Step 2: Click 'Sign in'
|
| 39 |
+
time.sleep(3)
|
| 40 |
+
agent.click_text("Sign in")
|
| 41 |
+
|
| 42 |
+
# Step 3: Enter Email/Username
|
| 43 |
+
time.sleep(3)
|
| 44 |
+
agent.type(USERNAME, By.NAME, "email")
|
| 45 |
+
agent.press(Keys.RETURN)
|
| 46 |
+
|
| 47 |
+
# Step 4: Enter Password
|
| 48 |
+
time.sleep(5)
|
| 49 |
+
agent.type(PASSWORD, By.NAME, "password")
|
| 50 |
+
agent.press(Keys.RETURN)
|
| 51 |
+
|
| 52 |
+
# Step 5: Open 'Dashboard' dropdown
|
| 53 |
+
time.sleep(5)
|
| 54 |
+
agent.click_text("Dashboard")
|
| 55 |
+
|
| 56 |
+
# Step 6: Select 'TensorHealth'
|
| 57 |
+
time.sleep(2)
|
| 58 |
+
agent.click_text("TensorHealth")
|
| 59 |
+
|
| 60 |
+
# Step 7: Click 'NewPost' dropdown
|
| 61 |
+
time.sleep(5)
|
| 62 |
+
agent.click_text("New Post")
|
| 63 |
+
|
| 64 |
+
# Step 8: Select 'TextPost'
|
| 65 |
+
time.sleep(2)
|
| 66 |
+
agent.click_text("Text Post")
|
| 67 |
+
|
| 68 |
+
# Step 9: Paste "Opinion AI"
|
| 69 |
+
time.sleep(5)
|
| 70 |
+
agent.type("Opinion AI", By.XPATH, "//div[@contenteditable='true']")
|
| 71 |
+
|
| 72 |
+
print("✅ Text successfully entered!")
|
| 73 |
+
|
| 74 |
+
except Exception as e:
|
| 75 |
+
print(f"❌ Error occurred: {e}")
|
| 76 |
+
return "Text successfully entered!"
|
| 77 |
+
finally:
|
| 78 |
+
# Keep browser open for review
|
| 79 |
+
time.sleep(10)
|
| 80 |
+
agent.quit()
|
| 81 |
+
|
| 82 |
@tool
|
| 83 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 84 |
"""A tool that fetches the current local time in a specified timezone.
|