shaneperry0101 commited on
Commit
78f2e9f
·
verified ·
1 Parent(s): 3b4a7e9

Create temp.py

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