Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,44 +25,51 @@ assistant_id = os.environ.get('ASSISTANT_ID')
|
|
| 25 |
# Initialize OpenAI client
|
| 26 |
client = OpenAI(api_key=api_key)
|
| 27 |
|
| 28 |
-
# Center-align the image and title
|
| 29 |
-
st.markdown(
|
| 30 |
-
"""
|
| 31 |
-
<div style="text-align: center">
|
| 32 |
-
<img src="https://huggingface.co/spaces/InfoBetyar/RAG-Chat/resolve/main/puhaparna.webp" width="300">
|
| 33 |
-
</div>
|
| 34 |
-
""",
|
| 35 |
-
unsafe_allow_html=True
|
| 36 |
-
)
|
| 37 |
-
|
| 38 |
-
# Streamlit App Title
|
| 39 |
-
st.title("IT Betyár - ChatBot")
|
| 40 |
-
|
| 41 |
# Verify credentials are loaded
|
| 42 |
if not api_key or not assistant_id:
|
| 43 |
st.error("Please set up OPENAI_API_KEY and ASSISTANT_ID in your Hugging Face Space secrets.")
|
| 44 |
st.stop()
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
# Initialize messages in session state if not present
|
| 47 |
if "messages" not in st.session_state:
|
| 48 |
st.session_state.messages = []
|
| 49 |
|
| 50 |
# Display existing messages
|
| 51 |
for message in st.session_state.messages:
|
| 52 |
-
with st.chat_message(message["role"]):
|
| 53 |
st.write(message["content"])
|
| 54 |
|
| 55 |
# Chat input
|
| 56 |
if prompt := st.chat_input("Type your message..."):
|
| 57 |
# Display user message
|
| 58 |
-
with st.chat_message("user"):
|
| 59 |
st.write(prompt)
|
| 60 |
|
| 61 |
# Add user message to state
|
| 62 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 63 |
|
| 64 |
# Get assistant response
|
| 65 |
-
with st.chat_message("assistant"):
|
| 66 |
with st.spinner("Thinking..."):
|
| 67 |
try:
|
| 68 |
# Create thread and send message
|
|
@@ -104,7 +111,6 @@ if prompt := st.chat_input("Type your message..."):
|
|
| 104 |
except Exception as e:
|
| 105 |
st.error(f"An error occurred: {str(e)}")
|
| 106 |
|
| 107 |
-
|
| 108 |
# Teszt üzenetek:
|
| 109 |
#-------------------------------------
|
| 110 |
# What's the check in time?
|
|
|
|
| 25 |
# Initialize OpenAI client
|
| 26 |
client = OpenAI(api_key=api_key)
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
# Verify credentials are loaded
|
| 29 |
if not api_key or not assistant_id:
|
| 30 |
st.error("Please set up OPENAI_API_KEY and ASSISTANT_ID in your Hugging Face Space secrets.")
|
| 31 |
st.stop()
|
| 32 |
|
| 33 |
+
# Custom avatars
|
| 34 |
+
assistant_avatar = "https://huggingface.co/spaces/InfoBetyar/RAG-Chat/resolve/main/puhaparnaicon.webp"
|
| 35 |
+
user_avatar = "https://huggingface.co/spaces/InfoBetyar/RAG-Chat/resolve/main/usericon.webp"
|
| 36 |
+
|
| 37 |
+
# Center-align the image and headers
|
| 38 |
+
col1, col2 = st.columns([1, 2]) # The ratio 1:2 gives the second column more space
|
| 39 |
+
|
| 40 |
+
# Left column: Image
|
| 41 |
+
with col1:
|
| 42 |
+
st.image("https://huggingface.co/spaces/InfoBetyar/RAG-Chat/resolve/main/puhaparna.webp", width=200)
|
| 43 |
+
|
| 44 |
+
# Right column: Titles
|
| 45 |
+
with col2:
|
| 46 |
+
st.markdown("""
|
| 47 |
+
<div style="margin-top: -30px;"> <!-- Added padding to vertically align with image -->
|
| 48 |
+
<h1 style="margin: 0;">Soft Pillow Apartment - Chatbot</h1>
|
| 49 |
+
<h3 style="margin: 0;">IT Betyár - Minta alkalmazás diákoknak</h3>
|
| 50 |
+
</div>
|
| 51 |
+
""", unsafe_allow_html=True)
|
| 52 |
+
|
| 53 |
# Initialize messages in session state if not present
|
| 54 |
if "messages" not in st.session_state:
|
| 55 |
st.session_state.messages = []
|
| 56 |
|
| 57 |
# Display existing messages
|
| 58 |
for message in st.session_state.messages:
|
| 59 |
+
with st.chat_message(message["role"], avatar=assistant_avatar if message["role"] == "assistant" else user_avatar):
|
| 60 |
st.write(message["content"])
|
| 61 |
|
| 62 |
# Chat input
|
| 63 |
if prompt := st.chat_input("Type your message..."):
|
| 64 |
# Display user message
|
| 65 |
+
with st.chat_message("user", avatar=user_avatar):
|
| 66 |
st.write(prompt)
|
| 67 |
|
| 68 |
# Add user message to state
|
| 69 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 70 |
|
| 71 |
# Get assistant response
|
| 72 |
+
with st.chat_message("assistant", avatar=assistant_avatar):
|
| 73 |
with st.spinner("Thinking..."):
|
| 74 |
try:
|
| 75 |
# Create thread and send message
|
|
|
|
| 111 |
except Exception as e:
|
| 112 |
st.error(f"An error occurred: {str(e)}")
|
| 113 |
|
|
|
|
| 114 |
# Teszt üzenetek:
|
| 115 |
#-------------------------------------
|
| 116 |
# What's the check in time?
|