Spaces:
Build error
Build error
File size: 1,395 Bytes
811902f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import cohere
import streamlit as st
cohere_api_key = ''
cohere_model_id = ''
def generate_ans(qstn):
response = co.generate(model=cohere_model_id,prompt=qstn)
bot_answer = response.generations[0].text
bot_answer = bot_answer.replace("\n\n--","").replace("\n--","").strip()
return bot_answer
# The front end code starts here
st.title("Question & answer bot with Cohere")
form = st.form(key="user_settings")
with form:
cohere_api_key = st.text_input('Cohere API Key:', type='password')
cohere_model_id = st.text_input('Cohere Model Id:')
if not cohere_api_key and not cohere_model_id:
st.info("Please add your Cohere API key and Custom model key or use 'medium/xlarge' to continue.")
update_api_keys = form.form_submit_button("Update keys")
st.stop()
co = cohere.Client(cohere_api_key)
st.write("Enter your qstn [Example: Who is the PM of UK] ")
qstn_input = st.text_input("Question", key = "qstn_input")
generate_button = form.form_submit_button("Answer Question")
if generate_button:
if qstn_input == "":
st.error("Question field cannot be blank")
else:
my_bar = st.progress(0.05)
st.subheader("Answer from bot:")
for i in range(1):
st.markdown("""---""")
ans = generate_ans(qstn_input)
st.markdown("##### " + ans)
st.write(ans)
my_bar.progress((i+1)/1)
|