Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -59,10 +59,7 @@ input_container = st.container()
|
|
59 |
with chat_container:
|
60 |
st.subheader("Conversation")
|
61 |
for idx, (speaker, message) in enumerate(st.session_state["conversation"]):
|
62 |
-
|
63 |
-
st.write(f"You ({idx}):", message, key=f"you_{idx}", disabled=False)
|
64 |
-
else:
|
65 |
-
st.write(f"Model ({idx}):", message, key=f"model_{idx}", disabled=False)
|
66 |
|
67 |
# Input Area
|
68 |
with input_container:
|
@@ -71,20 +68,23 @@ with input_container:
|
|
71 |
"Enter your query:",
|
72 |
value=st.session_state["user_input"], # Use session state for persistence
|
73 |
key="chat_input",
|
74 |
-
label_visibility="visible",
|
75 |
-
on_change=lambda: st.session_state.update({"user_input": st.session_state.chat_input}),
|
76 |
)
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
# Clear Conversation
|
90 |
if clear_conversation_button:
|
|
|
59 |
with chat_container:
|
60 |
st.subheader("Conversation")
|
61 |
for idx, (speaker, message) in enumerate(st.session_state["conversation"]):
|
62 |
+
st.markdown(f"**{speaker}:** {message}")
|
|
|
|
|
|
|
63 |
|
64 |
# Input Area
|
65 |
with input_container:
|
|
|
68 |
"Enter your query:",
|
69 |
value=st.session_state["user_input"], # Use session state for persistence
|
70 |
key="chat_input",
|
|
|
|
|
71 |
)
|
72 |
+
send_button_clicked = st.button("Send", key="send_button")
|
73 |
+
if send_button_clicked and user_input.strip():
|
74 |
+
# Process the input
|
75 |
+
with st.spinner("Generating response..."):
|
76 |
+
try:
|
77 |
+
response = st.session_state["qa_pipeline"](f"Q: {user_input}", max_length=400)
|
78 |
+
generated_text = response[0]["generated_text"]
|
79 |
+
|
80 |
+
# Append to conversation
|
81 |
+
st.session_state["conversation"].append(("You", user_input))
|
82 |
+
st.session_state["conversation"].append(("Model", generated_text))
|
83 |
+
|
84 |
+
# Clear input after submission
|
85 |
+
st.session_state["user_input"] = ""
|
86 |
+
except Exception as e:
|
87 |
+
st.error(f"Error generating response: {e}")
|
88 |
|
89 |
# Clear Conversation
|
90 |
if clear_conversation_button:
|