import streamlit as st from transformers import pipeline import torch # Load TinyLlama chatbot pipeline pipe = pipeline("text-generation", model="TinyLlama/TinyLlama-1.1B-Chat-v1.0", torch_dtype=torch.bfloat16, 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) response = pipe(prompt, max_new_tokens=256, do_sample=True, 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)