Spaces:
Sleeping
Sleeping
shaneperry0101
commited on
feat(app): add initial code
Browse files
app.py
CHANGED
@@ -1,4 +1,33 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
|
5 |
+
# Load the conversational model from Hugging Face
|
6 |
+
chatbot = pipeline('conversational', model='shaneperry0101/Health-Llama-3.2-1B')
|
7 |
+
|
8 |
+
# Initialize session state for storing the conversation
|
9 |
+
if 'conversation' not in st.session_state:
|
10 |
+
st.session_state.conversation = []
|
11 |
+
|
12 |
+
# Streamlit app layout
|
13 |
+
st.title("Chatbot Application")
|
14 |
+
user_input = st.text_input("You:", key="input")
|
15 |
+
|
16 |
+
if st.button("Send"):
|
17 |
+
if user_input:
|
18 |
+
# Append user input to the conversation
|
19 |
+
st.session_state.conversation.append({"role": "user", "content": user_input})
|
20 |
+
|
21 |
+
# Generate response
|
22 |
+
response = chatbot(user_input)
|
23 |
+
bot_response = response[0]['generated_text']
|
24 |
+
|
25 |
+
# Append bot response to the conversation
|
26 |
+
st.session_state.conversation.append({"role": "bot", "content": bot_response})
|
27 |
+
|
28 |
+
# Display the conversation
|
29 |
+
for message in st.session_state.conversation:
|
30 |
+
if message["role"] == "user":
|
31 |
+
st.text_area("You:", value=message["content"], key=f"user_{message['content']}", height=50)
|
32 |
+
else:
|
33 |
+
st.text_area("Bot:", value=message["content"], key=f"bot_{message['content']}", height=50)
|