chatbot / app.py
wissem29's picture
Upload app.py
be6f5ff verified
raw
history blame
1.01 kB
from langchain import HuggingFaceHub
from langchain.schema import AIMessage
from dotenv import load_dotenv
import streamlit as st
# Load environment variables
load_dotenv()
# Initialize HuggingFace model outside the app
llm_huggingface = HuggingFaceHub(repo_id="google/flan-t5-large", model_kwargs={"temperature": 0.0, "max_length": 64})
# Streamlit app
st.set_page_config(page_title="Chatbot")
st.header('Langchain Application')
# Remove the session_state initialization as it's not being used in this example
# Function to load HuggingFace model and get response
def get_huggingface_response(question):
response = llm_huggingface(question)
return response
# Streamlit input
user_input = st.text_input("Input: ", key="input")
# Streamlit button
submit = st.button('Generate')
# Check if button is clicked
if submit:
# Call function to get response
response = get_huggingface_response(user_input)
# Display response
st.subheader("The response is ")
st.write(response)