Update chatbot_bedrock.py
Browse files- chatbot_bedrock.py +14 -26
chatbot_bedrock.py
CHANGED
|
@@ -5,37 +5,25 @@ from langchain.chains import ConversationChain
|
|
| 5 |
import langchain.globals
|
| 6 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 7 |
import streamlit as st
|
| 8 |
-
from
|
| 9 |
|
| 10 |
-
class HuggingFaceModelWrapper(Runnable): # Assuming Runnable is the required interface
|
| 11 |
-
def __init__(self, model, tokenizer):
|
| 12 |
-
self.model = model
|
| 13 |
-
self.tokenizer = tokenizer
|
| 14 |
-
|
| 15 |
-
def run(self, input_text):
|
| 16 |
-
# Convert the input text to tokens
|
| 17 |
-
input_ids = self.tokenizer.encode(input_text, return_tensors="pt")
|
| 18 |
-
|
| 19 |
-
# Generate a response from the model
|
| 20 |
-
output = self.model.generate(input_ids, max_length=100, num_return_sequences=1)
|
| 21 |
-
|
| 22 |
-
# Decode the generated tokens to a string
|
| 23 |
-
response_text = self.tokenizer.decode(output[0], skip_special_tokens=True)
|
| 24 |
-
return response_text
|
| 25 |
-
def invoke(self, *args, **kwargs):
|
| 26 |
-
# Implement the 'invoke' method as required by the abstract base class/interface
|
| 27 |
-
# The implementation here depends on what 'invoke' is supposed to do. As an example:
|
| 28 |
-
|
| 29 |
-
# Assuming 'invoke' should process some input and return a model response
|
| 30 |
-
input_text = args[0] if args else kwargs.get('input_text', '')
|
| 31 |
-
return self.run(input_text)
|
| 32 |
|
| 33 |
|
| 34 |
@st.cache_resource
|
| 35 |
def load_model():
|
| 36 |
-
tokenizer = AutoTokenizer.from_pretrained("KvrParaskevi/Hotel-Assistant-Attempt4-Llama-2-7b")
|
| 37 |
-
model = AutoModelForCausalLM.from_pretrained("KvrParaskevi/Hotel-Assistant-Attempt4-Llama-2-7b")
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
def demo_miny_memory(model):
|
| 41 |
# llm_data = get_Model(hugging_face_key)
|
|
|
|
| 5 |
import langchain.globals
|
| 6 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 7 |
import streamlit as st
|
| 8 |
+
from langchain_community.llms import HuggingFaceHub
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
@st.cache_resource
|
| 13 |
def load_model():
|
| 14 |
+
#tokenizer = AutoTokenizer.from_pretrained("KvrParaskevi/Hotel-Assistant-Attempt4-Llama-2-7b")
|
| 15 |
+
#model = AutoModelForCausalLM.from_pretrained("KvrParaskevi/Hotel-Assistant-Attempt4-Llama-2-7b")
|
| 16 |
+
model = HuggingFaceHub(
|
| 17 |
+
repo_id="KvrParaskevi/Hotel-Assistant-Attempt4-Llama-2-7b",
|
| 18 |
+
task="text-generation",
|
| 19 |
+
model_kwargs={
|
| 20 |
+
"max_new_tokens": 512,
|
| 21 |
+
"top_k": 30,
|
| 22 |
+
"temperature": 0.1,
|
| 23 |
+
"repetition_penalty": 1.03,
|
| 24 |
+
},
|
| 25 |
+
)
|
| 26 |
+
return model
|
| 27 |
|
| 28 |
def demo_miny_memory(model):
|
| 29 |
# llm_data = get_Model(hugging_face_key)
|