File size: 1,132 Bytes
8e9272d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
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)