File size: 1,007 Bytes
8e9272d be6f5ff 8e9272d be6f5ff 8e9272d be6f5ff 8e9272d be6f5ff 8e9272d be6f5ff 8e9272d be6f5ff 8e9272d be6f5ff 8e9272d be6f5ff 8e9272d be6f5ff 8e9272d be6f5ff 8e9272d be6f5ff |
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 |
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)
|