ritampatra commited on
Commit
af8463a
·
verified ·
1 Parent(s): 3134b33

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+ chatbot = pipeline(task="text2text-generation", model="facebook/blenderbot-400M-distill")
4
+
5
+ st.title("Assistant pro")
6
+ if "messages" not in st.session_state:
7
+ st.session_state.messages = []
8
+
9
+ # Add a welcome message
10
+ welcome_message = "Welcome to the chat! How can I assist you today?"
11
+ st.session_state.messages.append({"role": "bot", "content": welcome_message})
12
+ for message in st.session_state.messages:
13
+ with st.chat_message(message["role"]):
14
+ st.markdown(message["content"])
15
+
16
+ if prompt := st.chat_input("What is up?"):
17
+
18
+ with st.chat_message("user"):
19
+ st.markdown(prompt)
20
+
21
+ st.session_state.messages.append({"role": "user", "content": prompt})
22
+ response = chatbot(prompt)[0]['generated_text']
23
+
24
+ with st.chat_message("bot"):
25
+ st.markdown(response)
26
+ st.session_state.messages.append({"role": "bot", "content": response})