Spaces:
Sleeping
Sleeping
currently selecting a random 2 and working through!
Browse files- app.py +13 -9
- helpers.py +4 -2
app.py
CHANGED
@@ -1,14 +1,20 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
|
3 |
# Set Streamlit to wide mode
|
4 |
st.set_page_config(layout="wide")
|
5 |
|
6 |
# Define the function to process the question
|
7 |
def ProcessQuestion(question):
|
8 |
-
#
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
12 |
return answer_a, answer_b
|
13 |
|
14 |
# Initialize session state if not already done
|
@@ -18,8 +24,6 @@ if 'answer_a' not in st.session_state:
|
|
18 |
st.session_state['answer_a'] = ""
|
19 |
if 'answer_b' not in st.session_state:
|
20 |
st.session_state['answer_b'] = ""
|
21 |
-
if 'selected_model' not in st.session_state:
|
22 |
-
st.session_state['selected_model'] = ""
|
23 |
if 'question' not in st.session_state:
|
24 |
st.session_state['question'] = ""
|
25 |
|
@@ -51,18 +55,18 @@ if submit_button:
|
|
51 |
else:
|
52 |
st.error("Your question exceeds the 1,000 character limit. Please shorten your question.")
|
53 |
else:
|
54 |
-
st.error("Please enter a question
|
55 |
|
56 |
# Display results if available in session state
|
57 |
if st.session_state['results_displayed']:
|
58 |
col1, col2 = st.columns(2)
|
59 |
|
60 |
with col1:
|
61 |
-
st.write(
|
62 |
st.write(st.session_state['answer_a'])
|
63 |
|
64 |
with col2:
|
65 |
-
st.write(
|
66 |
st.write(st.session_state['answer_b'])
|
67 |
|
68 |
feedback_col = st.columns([1, 1, 1, 1])
|
|
|
1 |
import streamlit as st
|
2 |
+
import random
|
3 |
+
from helpers import query_you_com, query_tavily, query_perplexity
|
4 |
|
5 |
# Set Streamlit to wide mode
|
6 |
st.set_page_config(layout="wide")
|
7 |
|
8 |
# Define the function to process the question
|
9 |
def ProcessQuestion(question):
|
10 |
+
# Randomly select two out of the three functions
|
11 |
+
functions = [query_you_com, query_tavily, query_perplexity]
|
12 |
+
selected_functions = random.sample(functions, 2)
|
13 |
+
|
14 |
+
# Get answers from the selected functions
|
15 |
+
answer_a = selected_functions[0](question)
|
16 |
+
answer_b = selected_functions[1](question)
|
17 |
+
|
18 |
return answer_a, answer_b
|
19 |
|
20 |
# Initialize session state if not already done
|
|
|
24 |
st.session_state['answer_a'] = ""
|
25 |
if 'answer_b' not in st.session_state:
|
26 |
st.session_state['answer_b'] = ""
|
|
|
|
|
27 |
if 'question' not in st.session_state:
|
28 |
st.session_state['question'] = ""
|
29 |
|
|
|
55 |
else:
|
56 |
st.error("Your question exceeds the 1,000 character limit. Please shorten your question.")
|
57 |
else:
|
58 |
+
st.error("Please enter a question.")
|
59 |
|
60 |
# Display results if available in session state
|
61 |
if st.session_state['results_displayed']:
|
62 |
col1, col2 = st.columns(2)
|
63 |
|
64 |
with col1:
|
65 |
+
st.write("### Output A")
|
66 |
st.write(st.session_state['answer_a'])
|
67 |
|
68 |
with col2:
|
69 |
+
st.write("### Output B")
|
70 |
st.write(st.session_state['answer_b'])
|
71 |
|
72 |
feedback_col = st.columns([1, 1, 1, 1])
|
helpers.py
CHANGED
@@ -21,7 +21,8 @@ def query_you_com(query):
|
|
21 |
headers=headers,
|
22 |
)
|
23 |
response.raise_for_status() # Raises an HTTPError if the response code was unsuccessful
|
24 |
-
|
|
|
25 |
except requests.exceptions.HTTPError as http_err:
|
26 |
return f"HTTP error occurred: {http_err}"
|
27 |
except Exception as err:
|
@@ -42,7 +43,8 @@ def query_tavily(query):
|
|
42 |
}
|
43 |
response = requests.post("https://api.tavily.com/search", json=payload)
|
44 |
if response.status_code == 200:
|
45 |
-
|
|
|
46 |
else:
|
47 |
return f"Request failed with status code: {response.status_code}"
|
48 |
|
|
|
21 |
headers=headers,
|
22 |
)
|
23 |
response.raise_for_status() # Raises an HTTPError if the response code was unsuccessful
|
24 |
+
resp = response.json()
|
25 |
+
return resp['answer']
|
26 |
except requests.exceptions.HTTPError as http_err:
|
27 |
return f"HTTP error occurred: {http_err}"
|
28 |
except Exception as err:
|
|
|
43 |
}
|
44 |
response = requests.post("https://api.tavily.com/search", json=payload)
|
45 |
if response.status_code == 200:
|
46 |
+
resp = response.json()
|
47 |
+
return resp['answer']
|
48 |
else:
|
49 |
return f"Request failed with status code: {response.status_code}"
|
50 |
|