|
import streamlit as st |
|
from transformers import pipeline |
|
|
|
|
|
|
|
|
|
chatbot = pipeline('text-generation', model='microsoft/DialoGPT-medium') |
|
|
|
|
|
if 'conversation' not in st.session_state: |
|
st.session_state.conversation = [] |
|
|
|
|
|
st.title("Chatbot Application") |
|
user_input = st.text_input("You:", key="input") |
|
|
|
if st.button("Send"): |
|
if user_input: |
|
|
|
st.session_state.conversation.append({"role": "user", "content": user_input}) |
|
|
|
|
|
response = chatbot(user_input) |
|
bot_response = response[0]['generated_text'] |
|
|
|
|
|
st.session_state.conversation.append({"role": "bot", "content": bot_response}) |
|
|
|
|
|
for message in st.session_state.conversation: |
|
if message["role"] == "user": |
|
st.text_area("You:", value=message["content"], key=f"user_{message['content']}", height=50) |
|
else: |
|
st.text_area("Bot:", value=message["content"], key=f"bot_{message['content']}", height=50) |
|
|