AyyAsk / backend /qa.py
xzxyx's picture
Duplicate from abxhr/design-project
b71b65d
import streamlit as st
from .qa_utils import annotate_answer
from .services import get_qa_answers
def write():
_, col1, _ = st.columns(3)
with col1:
st.title("Ask any question!")
st.markdown(
"""
<style>
p, div, input, label {
text-align: right;
}
</style>
""",
unsafe_allow_html=True,
)
st.sidebar.write("\n")
n_answers = st.sidebar.slider(
"Max. number of answers", min_value=1, max_value=10, value=2, step=1
)
question = st.text_input("", value="من هو جو بايدن؟")
if "؟" not in question:
question += "؟"
run_query = st.button("Find answers")
if run_query:
# https://discuss.streamlit.io/t/showing-a-gif-while-st-spinner-runs/5084
with st.spinner("Searching..."):
results_dict = get_qa_answers(question)
if len(results_dict) > 0:
st.write("## Answers:")
for result in results_dict["results"][:n_answers]:
annotate_answer(result)
f"[**Source**](<{result['link']}>)"
else:
st.write("## 😞 No results found.")