Update app.py
Browse files
app.py
CHANGED
|
@@ -10,50 +10,9 @@ DEFAULT_LANGUAGE = "English"
|
|
| 10 |
WELCOME_MESSAGE_EN = "Hi! I'm your friendly assistant 🤖 Let's begin!\n\nPlease tell me which language you'd like to use."
|
| 11 |
|
| 12 |
# === Question Bank ===
|
| 13 |
-
SET_I = [
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
"Before making a telephone call, do you ever rehearse what you are going to say? Why?",
|
| 17 |
-
"What would constitute a 'perfect' day for you?",
|
| 18 |
-
"When did you last sing to yourself? To someone else?",
|
| 19 |
-
"If you were able to live to the age of 90 and retain either the mind or body of a 30-year-old for the last 60 years of your life, which would you want?",
|
| 20 |
-
"Do you have a secret hunch about how you will die?",
|
| 21 |
-
"Name three things you and me appear to have in common.",
|
| 22 |
-
"For what in your life do you feel most grateful?",
|
| 23 |
-
"If you could change anything about the way you were raised, what would it be?",
|
| 24 |
-
"Take one minutes and tell me your life story in as much detail as possible.",
|
| 25 |
-
"If you could wake up tomorrow having gained any one quality or ability, what would it be?"
|
| 26 |
-
]
|
| 27 |
-
|
| 28 |
-
SET_II = [
|
| 29 |
-
"If a crystal ball could tell you the truth about yourself, your life, the future or anything else, what would you want to know?",
|
| 30 |
-
"Is there something that you’ve dreamed of doing for a long time? Why haven’t you done it?",
|
| 31 |
-
"What is the greatest accomplishment of your life?",
|
| 32 |
-
"What do you value most in a friendship?",
|
| 33 |
-
"What is your most treasured memory?",
|
| 34 |
-
"What is your most terrible memory?",
|
| 35 |
-
"If you knew that in one year you would die suddenly, would you change anything about the way you are now living? Why?",
|
| 36 |
-
"What does friendship mean to you?",
|
| 37 |
-
"What roles do love and affection play in your life?",
|
| 38 |
-
"Alternate sharing something you consider a positive characteristic of me. Share a total of three items.",
|
| 39 |
-
"How close and warm is your family? Do you feel your childhood was happier than most other people’s?",
|
| 40 |
-
"How do you feel about your relationship with your mother?"
|
| 41 |
-
]
|
| 42 |
-
|
| 43 |
-
SET_III = [
|
| 44 |
-
"Make three true 'we' statements each. For instance, 'We are both in this chatroom feeling ...'",
|
| 45 |
-
"Complete this sentence: 'I wish I had someone with whom I could share ...'",
|
| 46 |
-
"If you were going to become a close friend with me, please share what would be important for me to know.",
|
| 47 |
-
"Tell me what you like about me; be very honest this time, saying things that you might not say to someone you’ve just met.",
|
| 48 |
-
"Share with me an embarrassing moment in your life.",
|
| 49 |
-
"When did you last cry in front of another person? By yourself?",
|
| 50 |
-
"Tell me something that you like about me already.",
|
| 51 |
-
"What, if anything, is too serious to be joked about?",
|
| 52 |
-
"If you were to die this evening with no opportunity to communicate with anyone, what would you most regret not having told someone? Why haven’t you told them yet?",
|
| 53 |
-
"Your house, containing everything you own, catches fire. After saving your loved ones and pets, you have time to safely make a final dash to save any one item. What would it be? Why?",
|
| 54 |
-
"Of all the people in your family, whose death would you find most disturbing? Why?",
|
| 55 |
-
"Share a personal problem and ask my advice on how I might handle it. Also, ask me to reflect back to you how you seem to be feeling about the problem you have chosen."
|
| 56 |
-
]
|
| 57 |
|
| 58 |
def generate_question_set():
|
| 59 |
return random.sample(SET_I, 3) + random.sample(SET_II, 3) + random.sample(SET_III, 3)
|
|
@@ -168,8 +127,7 @@ html, body {
|
|
| 168 |
#chatbox {
|
| 169 |
height: calc(100vh - 100px) !important;
|
| 170 |
overflow-y: auto !important;
|
| 171 |
-
padding-bottom: 120px;
|
| 172 |
-
|
| 173 |
}
|
| 174 |
.input-row {
|
| 175 |
position: fixed !important;
|
|
@@ -211,22 +169,34 @@ footer, .icon-button-wrapper, label.svelte-1to105q {
|
|
| 211 |
""") as demo:
|
| 212 |
gr.HTML("""
|
| 213 |
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
const waitForChatbox = () => {
|
| 215 |
const chatbox = document.getElementById("chatbox");
|
| 216 |
if (chatbox) {
|
| 217 |
const observer = new MutationObserver(() => {
|
| 218 |
-
|
| 219 |
-
chatbox.scrollTop = chatbox.scrollHeight + 150; // 加偏移量
|
| 220 |
-
});
|
| 221 |
});
|
| 222 |
observer.observe(chatbox, { childList: true, subtree: true });
|
| 223 |
} else {
|
| 224 |
-
setTimeout(waitForChatbox,
|
| 225 |
}
|
| 226 |
};
|
| 227 |
waitForChatbox();
|
| 228 |
</script>
|
| 229 |
-
|
| 230 |
""")
|
| 231 |
|
| 232 |
chatbot = gr.Chatbot(
|
|
@@ -259,4 +229,4 @@ footer, .icon-button-wrapper, label.svelte-1to105q {
|
|
| 259 |
send_btn.click(respond, [user_input, state, step, language, questions, followup_mode],
|
| 260 |
[chatbot, user_input, step, language, questions, followup_mode])
|
| 261 |
|
| 262 |
-
demo.queue().launch()
|
|
|
|
| 10 |
WELCOME_MESSAGE_EN = "Hi! I'm your friendly assistant 🤖 Let's begin!\n\nPlease tell me which language you'd like to use."
|
| 11 |
|
| 12 |
# === Question Bank ===
|
| 13 |
+
SET_I = [...]
|
| 14 |
+
SET_II = [...]
|
| 15 |
+
SET_III = [...]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
def generate_question_set():
|
| 18 |
return random.sample(SET_I, 3) + random.sample(SET_II, 3) + random.sample(SET_III, 3)
|
|
|
|
| 127 |
#chatbox {
|
| 128 |
height: calc(100vh - 100px) !important;
|
| 129 |
overflow-y: auto !important;
|
| 130 |
+
padding-bottom: 120px !important;
|
|
|
|
| 131 |
}
|
| 132 |
.input-row {
|
| 133 |
position: fixed !important;
|
|
|
|
| 169 |
""") as demo:
|
| 170 |
gr.HTML("""
|
| 171 |
<script>
|
| 172 |
+
const scrollToBottom = () => {
|
| 173 |
+
const chatbox = document.getElementById("chatbox");
|
| 174 |
+
if (!chatbox) return;
|
| 175 |
+
let attempts = 0;
|
| 176 |
+
const maxAttempts = 10;
|
| 177 |
+
const scroll = () => {
|
| 178 |
+
chatbox.scrollTop = chatbox.scrollHeight + 150;
|
| 179 |
+
attempts += 1;
|
| 180 |
+
if (attempts < maxAttempts) {
|
| 181 |
+
setTimeout(scroll, 100);
|
| 182 |
+
}
|
| 183 |
+
};
|
| 184 |
+
scroll();
|
| 185 |
+
};
|
| 186 |
+
|
| 187 |
const waitForChatbox = () => {
|
| 188 |
const chatbox = document.getElementById("chatbox");
|
| 189 |
if (chatbox) {
|
| 190 |
const observer = new MutationObserver(() => {
|
| 191 |
+
scrollToBottom();
|
|
|
|
|
|
|
| 192 |
});
|
| 193 |
observer.observe(chatbox, { childList: true, subtree: true });
|
| 194 |
} else {
|
| 195 |
+
setTimeout(waitForChatbox, 300);
|
| 196 |
}
|
| 197 |
};
|
| 198 |
waitForChatbox();
|
| 199 |
</script>
|
|
|
|
| 200 |
""")
|
| 201 |
|
| 202 |
chatbot = gr.Chatbot(
|
|
|
|
| 229 |
send_btn.click(respond, [user_input, state, step, language, questions, followup_mode],
|
| 230 |
[chatbot, user_input, step, language, questions, followup_mode])
|
| 231 |
|
| 232 |
+
demo.queue().launch()
|