File size: 896 Bytes
a96c72f
6d7b830
a96c72f
6d7b830
 
 
 
a96c72f
6d7b830
a96c72f
6d7b830
 
a96c72f
6d7b830
a96c72f
6d7b830
 
 
 
 
 
 
 
 
a96c72f
6d7b830
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
import streamlit as st
from transformers import pipeline

@st.cache_resource
def load_model():
    chatbot = pipeline("conversational", model="facebook/blenderbot-400M-distill")
    return chatbot

st.title("Український Чат-бот")

if "history" not in st.session_state:
    st.session_state.history = []

user_input = st.text_input("Ви:", "")

if st.button("Надіслати"):
    chatbot = load_model()
    response = chatbot(st.session_state.history + [{"role": "user", "content": user_input}])
    st.session_state.history.extend([{"role": "user", "content": user_input}, {"role": "assistant", "content": response.generated_responses[0]}])

if st.session_state.history:
    for message in st.session_state.history:
        if message["role"] == "user":
            st.write(f"Ви: {message['content']}")
        else:
            st.write(f"Бот: {message['content']}")