Spaces:
Runtime error
Runtime error
eaglelandsonce
commited on
Commit
•
34d4587
1
Parent(s):
703b8c7
Update app.py
Browse files
app.py
CHANGED
@@ -26,7 +26,7 @@ def get_post_headers() -> dict:
|
|
26 |
"Content-Type": "application/json",
|
27 |
}
|
28 |
|
29 |
-
def query_vectara(query: str,
|
30 |
corpus_key = {
|
31 |
"customerId": customer_id,
|
32 |
"corpusId": corpus_id,
|
@@ -58,8 +58,8 @@ def query_vectara(query: str, case_number: int, filter_str="", lambda_val=0.0) -
|
|
58 |
}
|
59 |
|
60 |
response = requests.post(
|
|
|
61 |
headers=get_post_headers(),
|
62 |
-
url="https://api.vectara.io/v1/query",
|
63 |
data=json.dumps(data),
|
64 |
timeout=130,
|
65 |
)
|
@@ -73,19 +73,12 @@ def query_vectara(query: str, case_number: int, filter_str="", lambda_val=0.0) -
|
|
73 |
answer = result["responseSet"][0]["summary"][0]["text"]
|
74 |
return re.sub(r'\[\d+(,\d+){0,5}\]', '', answer)
|
75 |
|
76 |
-
|
77 |
# Title
|
78 |
st.title('Vectara Query Interface')
|
79 |
|
80 |
-
#
|
81 |
case_number = st.selectbox("Select Case Number:", range(2001, 2099), format_func=lambda x: f"Case Number = {x}")
|
82 |
|
83 |
-
# User input for query
|
84 |
-
user_query = st.text_input("Enter your query:", "")
|
85 |
-
|
86 |
-
# Display case number with query input
|
87 |
-
combined_query = f"{user_query} for {case_number}" if user_query else ""
|
88 |
-
|
89 |
# Advanced options
|
90 |
st.sidebar.header("Advanced Options")
|
91 |
filter_str = st.sidebar.text_input("Filter String:", "")
|
@@ -93,15 +86,11 @@ lambda_val = st.sidebar.slider("Lambda Value:", min_value=0.0, max_value=1.0, va
|
|
93 |
|
94 |
# Search button
|
95 |
if st.button('Search'):
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
st.write(output)
|
102 |
-
else:
|
103 |
-
st.error("Please enter a query to search.")
|
104 |
-
|
105 |
|
106 |
|
107 |
|
|
|
26 |
"Content-Type": "application/json",
|
27 |
}
|
28 |
|
29 |
+
def query_vectara(query: str, filter_str="", lambda_val=0.0) -> str:
|
30 |
corpus_key = {
|
31 |
"customerId": customer_id,
|
32 |
"corpusId": corpus_id,
|
|
|
58 |
}
|
59 |
|
60 |
response = requests.post(
|
61 |
+
"https://api.vectara.io/v1/query",
|
62 |
headers=get_post_headers(),
|
|
|
63 |
data=json.dumps(data),
|
64 |
timeout=130,
|
65 |
)
|
|
|
73 |
answer = result["responseSet"][0]["summary"][0]["text"]
|
74 |
return re.sub(r'\[\d+(,\d+){0,5}\]', '', answer)
|
75 |
|
|
|
76 |
# Title
|
77 |
st.title('Vectara Query Interface')
|
78 |
|
79 |
+
# Dropdown for selecting case number as the query
|
80 |
case_number = st.selectbox("Select Case Number:", range(2001, 2099), format_func=lambda x: f"Case Number = {x}")
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
# Advanced options
|
83 |
st.sidebar.header("Advanced Options")
|
84 |
filter_str = st.sidebar.text_input("Filter String:", "")
|
|
|
86 |
|
87 |
# Search button
|
88 |
if st.button('Search'):
|
89 |
+
query_str = f"Case Number = {case_number}"
|
90 |
+
with st.spinner('Querying Vectara...'):
|
91 |
+
output = query_vectara(query_str, filter_str, lambda_val)
|
92 |
+
st.markdown("## Result")
|
93 |
+
st.write(output)
|
|
|
|
|
|
|
|
|
94 |
|
95 |
|
96 |
|