KvrParaskevi's picture
Update chatbot.py
8ab4ca8 verified
raw
history blame
No virus
1.53 kB
import os
#from langchain import PromptTemplate, HuggingFaceHub, LLMChain
from langchain.memory import ConversationBufferMemory
from langchain.chains import ConversationChain
import langchain.globals
from transformers import AutoModelForCausalLM, AutoTokenizer
import streamlit as st
from langchain_community.llms import HuggingFaceHub
from transformers import pipeline
my_model_id = os.getenv('MODEL_REPO_ID', 'Default Value')
token = os.getenv('HUGGINGFACEHUB_API_TOKEN')
@st.cache_resource
def load_model():
#tokenizer = AutoTokenizer.from_pretrained("KvrParaskevi/Hotel-Assistant-Attempt4-Llama-2-7b")
#model = AutoModelForCausalLM.from_pretrained("KvrParaskevi/Hotel-Assistant-Attempt4-Llama-2-7b")
# Replace 'username/model_name' with your model's identifier on the Hugging Face Model Hub
model_identifier = "KvrParaskevi/Hotel-Assistant-Attempt4-Llama-2-7b"
task = "text-classification" # Change this to your model's task
# Load the model using the pipeline
model_pipeline = pipeline(task, model=model_identifier)
return model_pipeline
def demo_miny_memory(model):
# llm_data = get_Model(hugging_face_key)
memory = ConversationBufferMemory(llm = model,max_token_limit = 512)
return memory
def demo_chain(input_text, memory,model):
# llm_data = get_Model(hugging_face_key)
llm_conversation = ConversationChain(llm=model,memory=memory,verbose=langchain.globals.get_verbose())
chat_reply = llm_conversation.predict(input=input_text)
return chat_reply