ChatModel_Demo / app.py
JamalAG's picture
Update app.py
0a91ae1
raw
history blame
1 kB
import streamlit as st
from transformers import pipeline
# Load TinyLlama chatbot pipeline
pipe = pipeline("text-generation", model="TinyLlama/TinyLlama-1.1B-Chat-v1.0", torch_dtype="float32", device_map="auto")
# Streamlit app header
st.set_page_config(page_title="Chatbot Demo", page_icon="🤖")
st.header("Chatbot Demo")
# Input for user message
user_message = st.text_input("You:", "")
if st.button("Send"):
# Use TinyLlama chatbot pipeline to generate a response
messages = [{"role": "system", "content": "You are a friendly chatbot who always responds in the style of a pirate"},
{"role": "user", "content": user_message}]
prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
# Generate response using TinyLlama
response = pipe(prompt, max_length=256, temperature=0.7, top_k=50, top_p=0.95)[0]["generated_text"]
# Display the model's response
st.text_area("Model Response:", response, height=100)