Skip to content

Commit

Permalink
Refactor streamlit ui to allow more samples (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
suchintan committed Mar 4, 2024
1 parent 065d298 commit 0495552
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 93 deletions.
42 changes: 20 additions & 22 deletions streamlit_app/visualizer/sample_data.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import json
from pydantic import BaseModel


def get_sample_url() -> str:
return "https://www.geico.com"
class SampleData(BaseModel):
name: str
url: str
navigation_goal: str
data_extraction_goal: str
navigation_payload: dict
extracted_information_schema: dict


def get_sample_navigation_goal() -> str:
return "Navigate through the website until you generate an auto insurance quote. Do not generate a home insurance quote. If this page contains an auto insurance quote, consider the goal achieved"


def get_sample_data_extraction_goal() -> str:
return "Extract all quote information in JSON format including the premium amount, the timeframe for the quote."


def get_sample_navigation_payload() -> str:
navigation_payload = {
geico_sample_data = SampleData(
name="Geico",
url="https://www.geico.com",
navigation_goal="Navigate through the website until you generate an auto insurance quote. Do not generate a home insurance quote. If this page contains an auto insurance quote, consider the goal achieved",
data_extraction_goal="Extract all quote information in JSON format including the premium amount, the timeframe for the quote.",
navigation_payload={
"licensed_at_age": 19,
"education_level": "HIGH_SCHOOL",
"phone_number": "8042221111",
Expand Down Expand Up @@ -97,13 +98,8 @@ def get_sample_navigation_payload() -> str:
"spouse_education_level": "MASTERS",
"spouse_email": "amy.stake@abc.com",
"spouse_added_to_auto_policy": True,
}

return json.dumps(navigation_payload)


def get_sample_extracted_information_schema() -> str:
extracted_information_schema = {
},
extracted_information_schema={
"additionalProperties": False,
"properties": {
"quotes": {
Expand Down Expand Up @@ -181,5 +177,7 @@ def get_sample_extracted_information_schema() -> str:
}
},
"type": "object",
}
return json.dumps(extracted_information_schema)
},
)

supported_examples = [geico_sample_data]
147 changes: 76 additions & 71 deletions streamlit_app/visualizer/streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@
streamlit_show_recording,
)
from streamlit_app.visualizer.repository import TaskRepository
from streamlit_app.visualizer.sample_data import (
get_sample_data_extraction_goal,
get_sample_extracted_information_schema,
get_sample_navigation_goal,
get_sample_navigation_payload,
get_sample_url,
)
from streamlit_app.visualizer.sample_data import supported_examples

# Streamlit UI Configuration
st.set_page_config(layout="wide")
Expand Down Expand Up @@ -111,70 +105,81 @@ def select_step(step: dict) -> None:
execute_tab, visualizer_tab = st.tabs(["Execute", "Visualizer"])

with execute_tab:
create_column, explanation_column = st.columns([1, 2])
with create_column:
with st.form("task_form"):
st.markdown("## Run a task")
# Create all the fields to create a TaskRequest object
st_url = st.text_input("URL*", value=get_sample_url(), key="url")
st_webhook_callback_url = st.text_input("Webhook Callback URL", key="webhook", placeholder="Optional")
st_navigation_goal = st.text_input(
"Navigation Goal",
key="nav_goal",
placeholder="Describe the navigation goal",
value=get_sample_navigation_goal(),
)
st_data_extraction_goal = st.text_input(
"Data Extraction Goal",
key="data_goal",
placeholder="Describe the data extraction goal",
value=get_sample_data_extraction_goal(),
)
st_navigation_payload = st.text_area(
"Navigation Payload JSON",
key="nav_payload",
placeholder='{"name": "John Doe", "email": "abc@123.com"}',
value=get_sample_navigation_payload(),
)
st_extracted_information_schema = st.text_area(
"Extracted Information Schema",
key="extracted_info_schema",
placeholder='{"quote_price": "float"}',
value=get_sample_extracted_information_schema(),
)
# Create a TaskRequest object from the form fields
task_request_body = TaskRequest(
url=st_url,
webhook_callback_url=st_webhook_callback_url,
navigation_goal=st_navigation_goal,
data_extraction_goal=st_data_extraction_goal,
proxy_location=ProxyLocation.NONE,
navigation_payload=st_navigation_payload,
extracted_information_schema=st_extracted_information_schema,
)
# Submit the form
if st.form_submit_button("Execute Task", use_container_width=True):
# Call the API to create a task
task_id = client.create_task(task_request_body)
if not task_id:
st.error("Failed to create task!")
else:
st.success("Task created successfully, task_id: " + task_id)

with explanation_column:
st.markdown("### **Task Request**")
st.markdown("#### **URL**")
st.markdown("The starting URL for the task.")
st.markdown("#### **Webhook Callback URL**")
st.markdown("The URL to call with the results when the task is completed.")
st.markdown("#### **Navigation Goal**")
st.markdown("The user's goal for the task. Nullable if the task is only for data extraction.")
st.markdown("#### **Data Extraction Goal**")
st.markdown("The user's goal for data extraction. Nullable if the task is only for navigation.")
st.markdown("#### **Navigation Payload**")
st.markdown("The user's details needed to achieve the task. AI will use this information as needed.")
st.markdown("#### **Extracted Information Schema**")
st.markdown("The requested schema of the extracted information for data extraction goal.")
example_tabs = st.tabs([supported_example.name for supported_example in supported_examples])

for i, example_tab in enumerate(example_tabs):
with example_tab:
create_column, explanation_column = st.columns([1, 2])
with create_column:
with st.form("task_form"):
st.markdown("## Run a task")
example = supported_examples[i]
# Create all the fields to create a TaskRequest object
st_url = st.text_input("URL*", value=example.url, key="url")
st_webhook_callback_url = st.text_input(
"Webhook Callback URL", key="webhook", placeholder="Optional"
)
st_navigation_goal = st.text_input(
"Navigation Goal",
key="nav_goal",
placeholder="Describe the navigation goal",
value=example.navigation_goal,
)
st_data_extraction_goal = st.text_input(
"Data Extraction Goal",
key="data_goal",
placeholder="Describe the data extraction goal",
value=example.data_extraction_goal,
)
st_navigation_payload = st.text_area(
"Navigation Payload JSON",
key="nav_payload",
placeholder='{"name": "John Doe", "email": "abc@123.com"}',
value=example.navigation_payload,
)
st_extracted_information_schema = st.text_area(
"Extracted Information Schema",
key="extracted_info_schema",
placeholder='{"quote_price": "float"}',
value=example.extracted_information_schema,
)
# Create a TaskRequest object from the form fields
task_request_body = TaskRequest(
url=st_url,
webhook_callback_url=st_webhook_callback_url,
navigation_goal=st_navigation_goal,
data_extraction_goal=st_data_extraction_goal,
proxy_location=ProxyLocation.NONE,
navigation_payload=st_navigation_payload,
extracted_information_schema=st_extracted_information_schema,
)
# Submit the form
if st.form_submit_button("Execute Task", use_container_width=True):
# Call the API to create a task
task_id = client.create_task(task_request_body)
if not task_id:
st.error("Failed to create task!")
else:
st.success("Task created successfully, task_id: " + task_id)

with explanation_column:
st.markdown("### **Task Request**")
st.markdown("#### **URL**")
st.markdown("The starting URL for the task.")
st.markdown("#### **Webhook Callback URL**")
st.markdown("The URL to call with the results when the task is completed.")
st.markdown("#### **Navigation Goal**")
st.markdown("The user's goal for the task. Nullable if the task is only for data extraction.")
st.markdown("#### **Data Extraction Goal**")
st.markdown("The user's goal for data extraction. Nullable if the task is only for navigation.")
st.markdown("#### **Navigation Payload**")
st.markdown(
"The user's details needed to achieve the task. This is an unstructured field, and information can be passed in in any format you desire. Skyvern will map this information to the questions on the screen in real-time"
)
st.markdown("#### **Extracted Information Schema**")
st.markdown(
"(Optional) The requested schema of the extracted information for data extraction goal. This is a JSON object with keys as the field names and values as the data types. The data types can be any of the following: string, number, boolean, date, datetime, time, float, integer, object, array, null. If the schema is not provided, Skyvern will infer the schema from the extracted data."
)


with visualizer_tab:
Expand Down

0 comments on commit 0495552

Please sign in to comment.