chatbot / app.py
wissem29's picture
Upload 3 files
8e9272d verified
raw
history blame
1.13 kB
from langchain import HuggingFaceHub
from langchain.schema import HumanMessage,SystemMessage,AIMessage
from dotenv import load_dotenv
load_dotenv()
import streamlit as st
##streamlit app
st.set_page_config(page_title="Chatbot")
st.header('Langchain Application')
# Initialization session
##if 'key' not in st.session_state:
# st.session_state['key'] =[
# SystemMessage(content='You are AI ')
# ]
# function to load huggingface model and get response
def get_huggingface_response(question):
llm_huggingface=HuggingFaceHub(repo_id="google/flan-t5-large",model_kwargs={"temperature":0.0})
#st.session_state['key'].append(HumanMessage(content=question))
#response=llm_huggingface(st.session_state['key'])
response = llm_huggingface(question)
#st.session_state['key'].append(AIMessage(content=response))
return(response)
##streamlit input
input=st.text_input("Input: ",key="input")
## call function
response=get_huggingface_response(input)
##streamlit button
submit=st.button('Generate')
## click button
if submit:
st.subheader("The response is ")
st.write(response)