Spaces:
Sleeping
Sleeping
final UI
Browse files- frontend/app.py +11 -21
frontend/app.py
CHANGED
|
@@ -76,25 +76,13 @@ with st.sidebar:
|
|
| 76 |
ask_tab, challenge_tab = st.tabs(["Ask Anything", "Challenge Me"])
|
| 77 |
|
| 78 |
with ask_tab:
|
| 79 |
-
st.subheader("Document
|
| 80 |
-
|
| 81 |
-
st.session_state.chat_history = []
|
| 82 |
if st.session_state.current_file:
|
| 83 |
-
#
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
else:
|
| 88 |
-
st.markdown(f"**Assistant:** {msg['content']}")
|
| 89 |
-
|
| 90 |
-
# Chat input
|
| 91 |
-
user_question = st.text_input("Type your question and press Enter:", key="chat_input")
|
| 92 |
-
send = st.button("Send", key="send_chat")
|
| 93 |
-
if send and user_question.strip():
|
| 94 |
-
# Add user message to history
|
| 95 |
-
st.session_state.chat_history.append({"role": "user", "content": user_question})
|
| 96 |
-
|
| 97 |
-
# Send to backend
|
| 98 |
response = requests.post(
|
| 99 |
f"{BACKEND_URL}/chat",
|
| 100 |
json={
|
|
@@ -103,11 +91,13 @@ with ask_tab:
|
|
| 103 |
"model": "gpt-4o-mini"
|
| 104 |
}
|
| 105 |
)
|
|
|
|
| 106 |
if response.status_code == 200:
|
| 107 |
data = response.json()
|
| 108 |
-
|
| 109 |
-
st.
|
| 110 |
-
st.
|
|
|
|
| 111 |
else:
|
| 112 |
st.error("Failed to get response")
|
| 113 |
else:
|
|
|
|
| 76 |
ask_tab, challenge_tab = st.tabs(["Ask Anything", "Challenge Me"])
|
| 77 |
|
| 78 |
with ask_tab:
|
| 79 |
+
st.subheader("Document Q&A")
|
| 80 |
+
|
|
|
|
| 81 |
if st.session_state.current_file:
|
| 82 |
+
# Chat interface
|
| 83 |
+
user_question = st.text_input("Ask a question about the document:")
|
| 84 |
+
|
| 85 |
+
if user_question:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
response = requests.post(
|
| 87 |
f"{BACKEND_URL}/chat",
|
| 88 |
json={
|
|
|
|
| 91 |
"model": "gpt-4o-mini"
|
| 92 |
}
|
| 93 |
)
|
| 94 |
+
|
| 95 |
if response.status_code == 200:
|
| 96 |
data = response.json()
|
| 97 |
+
st.divider()
|
| 98 |
+
st.subheader("Answer")
|
| 99 |
+
st.write(data["answer"])
|
| 100 |
+
st.caption(f"Session ID: {data['session_id']}")
|
| 101 |
else:
|
| 102 |
st.error("Failed to get response")
|
| 103 |
else:
|