Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,8 +12,6 @@ MAX_CONTEXT_LENGTH = 4096 # Example: Adjust based on your model
|
|
12 |
################################
|
13 |
# SYSTEM PROMPT (PATIENT ROLE) #
|
14 |
################################
|
15 |
-
# This is the core text that tells the LLM to behave as the "patient."
|
16 |
-
# You can store it in "prompt.txt" or include it directly here as a string.
|
17 |
nvc_prompt_template = """
|
18 |
You are now taking on the role of a single user (a “patient”) seeking support for various personal and emotional challenges.
|
19 |
|
@@ -65,8 +63,8 @@ def respond(
|
|
65 |
|
66 |
# Truncate history to fit within max tokens
|
67 |
truncated_history = truncate_history(
|
68 |
-
history,
|
69 |
-
formatted_system_message,
|
70 |
MAX_CONTEXT_LENGTH - max_tokens - 100 # Reserve some space
|
71 |
)
|
72 |
|
@@ -100,24 +98,15 @@ def respond(
|
|
100 |
print(f"An error occurred: {e}")
|
101 |
yield "I'm sorry, I encountered an error. Please try again."
|
102 |
|
103 |
-
|
104 |
-
# INITIAL MESSAGE #
|
105 |
-
###################
|
106 |
-
# This is how we make the LLM "start" by playing the role of the user/patient.
|
107 |
-
# Essentially, we seed the conversation with an initial user message (from the LLM).
|
108 |
initial_user_message = (
|
109 |
-
"I really don’t know where to begin… I feel
|
110 |
-
"My neighbors keep playing loud music, I’m arguing with my partner about money
|
111 |
-
"
|
112 |
-
"I just feel powerless
|
113 |
)
|
114 |
|
115 |
# --- Gradio Interface ---
|
116 |
-
def start_conversation():
|
117 |
-
"""Creates the initial chat state, so the LLM 'as user' starts talking."""
|
118 |
-
# Return a conversation with a single user message: the LLM’s "patient" message
|
119 |
-
return [("Hi there!", initial_user_message)]
|
120 |
-
|
121 |
demo = gr.ChatInterface(
|
122 |
fn=respond,
|
123 |
additional_inputs=[
|
@@ -126,11 +115,9 @@ demo = gr.ChatInterface(
|
|
126 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
127 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
128 |
],
|
129 |
-
#
|
130 |
-
|
131 |
-
|
132 |
-
# Here we use a function that returns an initial conversation state:
|
133 |
-
chatbot = start_conversation()
|
134 |
)
|
135 |
|
136 |
if __name__ == "__main__":
|
|
|
12 |
################################
|
13 |
# SYSTEM PROMPT (PATIENT ROLE) #
|
14 |
################################
|
|
|
|
|
15 |
nvc_prompt_template = """
|
16 |
You are now taking on the role of a single user (a “patient”) seeking support for various personal and emotional challenges.
|
17 |
|
|
|
63 |
|
64 |
# Truncate history to fit within max tokens
|
65 |
truncated_history = truncate_history(
|
66 |
+
history,
|
67 |
+
formatted_system_message,
|
68 |
MAX_CONTEXT_LENGTH - max_tokens - 100 # Reserve some space
|
69 |
)
|
70 |
|
|
|
98 |
print(f"An error occurred: {e}")
|
99 |
yield "I'm sorry, I encountered an error. Please try again."
|
100 |
|
101 |
+
# OPTIONAL: An initial user message (the LLM "as user") if desired
|
|
|
|
|
|
|
|
|
102 |
initial_user_message = (
|
103 |
+
"I really don’t know where to begin… I feel overwhelmed lately. "
|
104 |
+
"My neighbors keep playing loud music, and I’m arguing with my partner about money. "
|
105 |
+
"Also, two of my friends are fighting, and the group is drifting apart. "
|
106 |
+
"I just feel powerless."
|
107 |
)
|
108 |
|
109 |
# --- Gradio Interface ---
|
|
|
|
|
|
|
|
|
|
|
110 |
demo = gr.ChatInterface(
|
111 |
fn=respond,
|
112 |
additional_inputs=[
|
|
|
115 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
116 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
117 |
],
|
118 |
+
# You can optionally set 'title' or 'description' to show some info in the UI:
|
119 |
+
title="NVC Patient Chatbot",
|
120 |
+
description="This chatbot behaves like a user/patient describing personal challenges."
|
|
|
|
|
121 |
)
|
122 |
|
123 |
if __name__ == "__main__":
|