Download app.py from HarshitX/ChatBot_With_Partial_Intelligence: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/HarshitX/ChatBot_With_Partial_Intelligence/resolve/main/app.py
- Command line
-
hf download hf://spaces/HarshitX/ChatBot_With_Partial_Intelligence/app.py
-
curl -L -o app.py https://huggingface.co/spaces/HarshitX/ChatBot_With_Partial_Intelligence/resolve/main/app.py
1.19 kB
| ## Conversational Q&A Chatbot | |
| import os | |
| import streamlit as st | |
| from dotenv import load_dotenv | |
| from langchain_community.chat_models import ChatOpenAI | |
| from langchain.schema import HumanMessage, SystemMessage, AIMessage | |
| load_dotenv() | |
| # Streamlit UI | |
| st.set_page_config(page_title="Conversational Q&A Chatbot", layout="centered") | |
| st.header("Hey! Let's Chat...") | |
| chat = ChatOpenAI(temperature=0.5) | |
| if 'flow_messages' not in st.session_state: | |
| st.session_state['flow_messages']=[ | |
| SystemMessage(content="You are a helpful Coding AI assistant.") | |
| ] | |
| # Functions to load OpenAI model and get responses | |
| def gen_openai_response(question): | |
| st.session_state["flow_messages"].append(HumanMessage(content=question)) | |
| answer = chat(st.session_state["flow_messages"]) | |
| st.session_state["flow_messages"].append(AIMessage(content=answer.content)) | |
| return answer.content | |
| user_input= st.text_input("Input: ",key="input") | |
| response= gen_openai_response(user_input) | |
| submit=st.button("Ask the question") | |
| if __name__ == "__main__": | |
| # If ask button is clicked | |
| if submit: | |
| st.subheader("The Response is") | |
| st.write(response) |