mirror of
https://github.com/Skyvern-AI/skyvern.git
synced 2025-09-02 02:30:07 +00:00
Refactor streamlit ui to allow more samples (#21)
This commit is contained in:
parent
065d2983fa
commit
0495552b11
2 changed files with 95 additions and 92 deletions
|
@ -1,20 +1,21 @@
|
||||||
import json
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
def get_sample_url() -> str:
|
class SampleData(BaseModel):
|
||||||
return "https://www.geico.com"
|
name: str
|
||||||
|
url: str
|
||||||
|
navigation_goal: str
|
||||||
|
data_extraction_goal: str
|
||||||
|
navigation_payload: dict
|
||||||
|
extracted_information_schema: dict
|
||||||
|
|
||||||
|
|
||||||
def get_sample_navigation_goal() -> str:
|
geico_sample_data = SampleData(
|
||||||
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"
|
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",
|
||||||
def get_sample_data_extraction_goal() -> str:
|
data_extraction_goal="Extract all quote information in JSON format including the premium amount, the timeframe for the quote.",
|
||||||
return "Extract all quote information in JSON format including the premium amount, the timeframe for the quote."
|
navigation_payload={
|
||||||
|
|
||||||
|
|
||||||
def get_sample_navigation_payload() -> str:
|
|
||||||
navigation_payload = {
|
|
||||||
"licensed_at_age": 19,
|
"licensed_at_age": 19,
|
||||||
"education_level": "HIGH_SCHOOL",
|
"education_level": "HIGH_SCHOOL",
|
||||||
"phone_number": "8042221111",
|
"phone_number": "8042221111",
|
||||||
|
@ -97,13 +98,8 @@ def get_sample_navigation_payload() -> str:
|
||||||
"spouse_education_level": "MASTERS",
|
"spouse_education_level": "MASTERS",
|
||||||
"spouse_email": "amy.stake@abc.com",
|
"spouse_email": "amy.stake@abc.com",
|
||||||
"spouse_added_to_auto_policy": True,
|
"spouse_added_to_auto_policy": True,
|
||||||
}
|
},
|
||||||
|
extracted_information_schema={
|
||||||
return json.dumps(navigation_payload)
|
|
||||||
|
|
||||||
|
|
||||||
def get_sample_extracted_information_schema() -> str:
|
|
||||||
extracted_information_schema = {
|
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
"properties": {
|
"properties": {
|
||||||
"quotes": {
|
"quotes": {
|
||||||
|
@ -181,5 +177,7 @@ def get_sample_extracted_information_schema() -> str:
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"type": "object",
|
"type": "object",
|
||||||
}
|
},
|
||||||
return json.dumps(extracted_information_schema)
|
)
|
||||||
|
|
||||||
|
supported_examples = [geico_sample_data]
|
||||||
|
|
|
@ -10,13 +10,7 @@ from streamlit_app.visualizer.artifact_loader import (
|
||||||
streamlit_show_recording,
|
streamlit_show_recording,
|
||||||
)
|
)
|
||||||
from streamlit_app.visualizer.repository import TaskRepository
|
from streamlit_app.visualizer.repository import TaskRepository
|
||||||
from streamlit_app.visualizer.sample_data import (
|
from streamlit_app.visualizer.sample_data import supported_examples
|
||||||
get_sample_data_extraction_goal,
|
|
||||||
get_sample_extracted_information_schema,
|
|
||||||
get_sample_navigation_goal,
|
|
||||||
get_sample_navigation_payload,
|
|
||||||
get_sample_url,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Streamlit UI Configuration
|
# Streamlit UI Configuration
|
||||||
st.set_page_config(layout="wide")
|
st.set_page_config(layout="wide")
|
||||||
|
@ -111,70 +105,81 @@ st.markdown(f"### **{select_env} - {select_org}**")
|
||||||
execute_tab, visualizer_tab = st.tabs(["Execute", "Visualizer"])
|
execute_tab, visualizer_tab = st.tabs(["Execute", "Visualizer"])
|
||||||
|
|
||||||
with execute_tab:
|
with execute_tab:
|
||||||
create_column, explanation_column = st.columns([1, 2])
|
example_tabs = st.tabs([supported_example.name for supported_example in supported_examples])
|
||||||
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:
|
for i, example_tab in enumerate(example_tabs):
|
||||||
st.markdown("### **Task Request**")
|
with example_tab:
|
||||||
st.markdown("#### **URL**")
|
create_column, explanation_column = st.columns([1, 2])
|
||||||
st.markdown("The starting URL for the task.")
|
with create_column:
|
||||||
st.markdown("#### **Webhook Callback URL**")
|
with st.form("task_form"):
|
||||||
st.markdown("The URL to call with the results when the task is completed.")
|
st.markdown("## Run a task")
|
||||||
st.markdown("#### **Navigation Goal**")
|
example = supported_examples[i]
|
||||||
st.markdown("The user's goal for the task. Nullable if the task is only for data extraction.")
|
# Create all the fields to create a TaskRequest object
|
||||||
st.markdown("#### **Data Extraction Goal**")
|
st_url = st.text_input("URL*", value=example.url, key="url")
|
||||||
st.markdown("The user's goal for data extraction. Nullable if the task is only for navigation.")
|
st_webhook_callback_url = st.text_input(
|
||||||
st.markdown("#### **Navigation Payload**")
|
"Webhook Callback URL", key="webhook", placeholder="Optional"
|
||||||
st.markdown("The user's details needed to achieve the task. AI will use this information as needed.")
|
)
|
||||||
st.markdown("#### **Extracted Information Schema**")
|
st_navigation_goal = st.text_input(
|
||||||
st.markdown("The requested schema of the extracted information for data extraction goal.")
|
"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:
|
with visualizer_tab:
|
||||||
|
|
Loading…
Add table
Reference in a new issue