File size: 995 Bytes
8bbfca2
926f3d7
9d8e92e
8bbfca2
926f3d7
 
8bbfca2
41fe4ff
926f3d7
 
9d8e92e
41fe4ff
 
8bbfca2
41fe4ff
926f3d7
 
 
 
 
41fe4ff
 
926f3d7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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)