mrmtaeb commited on
Commit
0409f21
·
verified ·
1 Parent(s): 16edc8c

Update src/interface/ui.py

Browse files
Files changed (1) hide show
  1. src/interface/ui.py +50 -30
src/interface/ui.py CHANGED
@@ -25,6 +25,18 @@ def create_interface(call_model):
25
  background-repeat: no-repeat;
26
  background-attachment: fixed;
27
  }}
 
 
 
 
 
 
 
 
 
 
 
 
28
  </style>
29
  """,
30
  unsafe_allow_html=True
@@ -40,37 +52,45 @@ def create_interface(call_model):
40
  st.markdown("<h1 style='color:black;'>ARGObot: UWF's Custom Q&A Chatbot</h1>", unsafe_allow_html=True)
41
 
42
  # Sample questions
43
- st.markdown("### Example questions:")
44
- st.markdown("- UWF's values")
45
- st.markdown("- Student Rights and Responsibilities")
46
- st.markdown("- Student Resources")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
- # Display conversation
49
- for message in st.session_state.chat_history:
50
- if isinstance(message, HumanMessage):
51
- st.markdown(f"<div style='background-color:#8DC8E8; padding:10px; border-radius:10px;'><strong>You:</strong> {message.content}</div>", unsafe_allow_html=True)
52
- elif isinstance(message, AIMessage):
53
- st.markdown(f"<div style='background-color:#E7E7E7; padding:10px; border-radius:10px;'><strong>Chatbot:</strong> {message.content}</div>", unsafe_allow_html=True)
54
 
55
- # Input form
56
- with st.form(key="chat_form", clear_on_submit=True):
57
- user_input = st.text_input("Enter your question here:")
58
- submitted = st.form_submit_button("Submit")
59
 
60
- if submitted:
61
- if user_input.strip():
62
- state = {
63
- "input": user_input,
64
- "chat_history": st.session_state.chat_history,
65
- "context": "",
66
- "answer": ""
67
- }
68
- result = call_model(state)
69
- if not result.get("answer"):
70
- result["answer"] = "Sorry, I couldn't generate an answer."
71
 
72
- st.session_state.chat_history.append(HumanMessage(user_input))
73
- st.session_state.chat_history.append(AIMessage(result["answer"]))
74
- st.rerun()
75
- else:
76
- st.warning("Please enter a question.")
 
25
  background-repeat: no-repeat;
26
  background-attachment: fixed;
27
  }}
28
+ h1 {{ color: #000000; }}
29
+ p {{ color: #000000; }}
30
+ .custom-caption {{ color: #A5A4A4; font-size: 16px; text-align: center; }}
31
+ .chat-bubble {{
32
+ max-width: 70%;
33
+ padding: 10px;
34
+ margin: 5px 0;
35
+ border-radius: 10px;
36
+ color: #000000;
37
+ }}
38
+ .human-message {{ background-color: #8DC8E8; align-self: flex-end; text-align: right; }}
39
+ .ai-message {{ background-color: #E7E7E7; align-self: flex-start; }}
40
  </style>
41
  """,
42
  unsafe_allow_html=True
 
52
  st.markdown("<h1 style='color:black;'>ARGObot: UWF's Custom Q&A Chatbot</h1>", unsafe_allow_html=True)
53
 
54
  # Sample questions
55
+ st.markdown("""
56
+ <div style='text-align: center; font-size: 20px; font-weight: normal;'>
57
+ <p style='font-size: 20px;'>Ask ARGObot a variety of questions based on the Student Handbook.</p>
58
+ </div>
59
+ """, unsafe_allow_html=True)
60
+
61
+ st.write("Example topics:")
62
+ st.markdown("<p style='color: #000000;'>- UWF's values</p>", unsafe_allow_html=True)
63
+ st.markdown("<p style='color: #000000;'>- Student Rights and Responsibilities</p>", unsafe_allow_html=True)
64
+ st.markdown("<p style='color: #000000;'>- UWF Policies and Regulations</p>", unsafe_allow_html=True)
65
+ st.markdown("<p style='color: #000000;'>- UWF Appeals and Student Grievance Processes</p>", unsafe_allow_html=True)
66
+ st.markdown("<p style='color: #000000;'>- Student Health and Wellbeing</p>", unsafe_allow_html=True)
67
+ st.markdown("<p style='color: #000000;'>- Student Resources</p>", unsafe_allow_html=True)
68
+
69
+ chat_container = st.container()
70
+
71
+ with chat_container:
72
+ st.markdown("<div class='chat-container'>", unsafe_allow_html=True)
73
+ for message in st.session_state.chat_history:
74
+ if isinstance(message, HumanMessage):
75
+ st.markdown(f"<div class='chat-bubble human-message'><strong>You:</strong> {message.content}</div>", unsafe_allow_html=True)
76
+ elif isinstance(message, AIMessage):
77
+ st.markdown(f"<div class='chat-bubble ai-message'><strong>Chatbot:</strong> {message.content}</div>", unsafe_allow_html=True)
78
+ st.markdown("</div>", unsafe_allow_html=True)
79
+
80
+ with st.form(key='question_form', clear_on_submit=True):
81
+ user_input = st.text_input("Enter your question here:", key="user_input")
82
+ submit_button = st.form_submit_button(label='Submit')
83
 
84
+ if submit_button and user_input:
85
+ state = {"input": user_input, "chat_history": st.session_state.chat_history, "context": "", "answer": ""}
86
+ result = call_model(state)
 
 
 
87
 
88
+ if not result.get("answer"):
89
+ result["answer"] = "Sorry, I couldn't generate an answer."
 
 
90
 
91
+ st.session_state.chat_history.append(HumanMessage(user_input))
92
+ st.session_state.chat_history.append(AIMessage(result["answer"]))
93
+ st.rerun()
 
 
 
 
 
 
 
 
94
 
95
+ elif submit_button:
96
+ st.warning("Please enter a question.")