Refactor streamlit ui to allow more samples (#21)

This commit is contained in:
Suchintan 2024-03-04 11:40:19 -05:00 committed by GitHub
parent 065d2983fa
commit 0495552b11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 95 additions and 92 deletions

View file

@ -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",
@ -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": {
@ -181,5 +177,7 @@ def get_sample_extracted_information_schema() -> str:
}
},
"type": "object",
}
return json.dumps(extracted_information_schema)
},
)
supported_examples = [geico_sample_data]

View file

@ -10,13 +10,7 @@ from streamlit_app.visualizer.artifact_loader import (
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")
@ -111,36 +105,43 @@ st.markdown(f"### **{select_env} - {select_org}**")
execute_tab, visualizer_tab = st.tabs(["Execute", "Visualizer"])
with execute_tab:
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=get_sample_url(), key="url")
st_webhook_callback_url = st.text_input("Webhook Callback URL", key="webhook", placeholder="Optional")
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=get_sample_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=get_sample_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=get_sample_navigation_payload(),
value=example.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(),
value=example.extracted_information_schema,
)
# Create a TaskRequest object from the form fields
task_request_body = TaskRequest(
@ -172,9 +173,13 @@ with execute_tab:
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(
"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("The requested schema of the extracted information for data extraction goal.")
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: