File size: 1,142 Bytes
e967447 3c86eaf f02d1d0 b8de5c6 885fb2e e967447 3c86eaf e967447 3c86eaf bb775e5 3c86eaf |
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 |
import streamlit as st
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
st.title("Generating Response with HuggingFace Models")
st.markdown("## Model: `facebook/blenderbot-400M-distill`")
with st.spinner("Getting this ready for you.."):
model_name = "facebook/blenderbot-400M-distill"
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
def get_response(input_text):
# Tokenize the input text and history
inputs = tokenizer.encode_plus(input_text, return_tensors="pt")
# Generate the response from the model
outputs = model.generate(**inputs)
# Decode the response
response = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
return response
user_input = st.text_area("Enter your query here...")
if st.button("Get Response") and user_input:
with st.spinner("Generating Response..."):
answer = get_response(user_input)
if answer is not None:
st.success('Great! Response generated successfully')
st.write(answer) |