CoolFace
Apppublic

shriti-somani/ChatModelApp

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py43 linesDownload Raw Back to root
1import streamlit as st2import os3import cohere4from langchain.schema import AIMessage, HumanMessage, SystemMessage5 6# Set the Cohere API key7os.environ["default"] = "8dTkfNNsSiWNi8DuHvZPVWwlUjS8jp5O7GzVyWWT"8 9# Initialize the Cohere client10cohere_client = cohere.Client(os.getenv("default"))11 12# Set the page configuration13st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")14st.header("Hey, I'm your Chat GPT")15 16if "sessionMessages" not in st.session_state:17    st.session_state.sessionMessages = [18        SystemMessage(content="You are a helpful assistant.")19    ]20 21def load_answer(question):22    st.session_state.sessionMessages.append(HumanMessage(content=question))23    response = cohere_client.generate(24        model='command-r-plus-08-2024',25        prompt=f"You are a helpful assistant. {question}",26        max_tokens=50,27        temperature=0.728    )29    assistant_answer = response.generations[0].text30    st.session_state.sessionMessages.append(AIMessage(content=assistant_answer))31    return assistant_answer32 33def get_text():34    input_text = st.text_input("You: ")35    return input_text36 37user_input = get_text()38submit = st.button('Generate')39 40if submit:41    response = load_answer(user_input)42    st.subheader("Answer:")43    st.write(response)