File size: 1,159 Bytes
f89c228
5bfff87
f89c228
600b6c0
cdb997d
f7f329c
600b6c0
f89c228
600b6c0
 
cdb997d
941c102
600b6c0
 
cdb997d
600b6c0
 
cdb997d
600b6c0
 
 
cdb997d
600b6c0
cdb997d
600b6c0
 
 
e0a1083
600b6c0
 
 
e0a1083
600b6c0
ab5f614
600b6c0
 
 
 
 
f89c228
600b6c0
 
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

import streamlit as st
from langchain.llms import Cohere
from streamlit_chat import message


def api_calling(question):
    model = Cohere(cohere_api_key='AwUrUmbrQPC8ROSvqGdSxlYM8TZjgfOYGxNmGaci')
    response = model.invoke(question)
    return  response  

st.title("COHERE CHATBOT MARDI.BADR")
if 'user_input' not in st.session_state:
	st.session_state['user_input'] = []

if 'cohere_response' not in st.session_state:
	st.session_state['cohere_response'] = []

def get_text():
	input_text = st.text_input("write here", key="input")
	return input_text

user_input = get_text()

if user_input:
	output = api_calling(user_input)
	output = output.lstrip("\n")

	# Store the output
	st.session_state.cohere_response.append(user_input)
	st.session_state.user_input.append(output)

message_history = st.empty()

if st.session_state['user_input']:
	for i in range(len(st.session_state['user_input']) - 1, -1, -1):
		# This function displays user input
		message(st.session_state["user_input"][i], 
				key=str(i),avatar_style="icons")
		message(st.session_state['cohere_response'][i], 
				avatar_style="miniavs",is_user=True,
				key=str(i) + 'data_by_user')