ndn1954 commited on
Commit
811902f
1 Parent(s): d211960

Upload app.py

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