Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,12 @@ import os
|
|
7 |
|
8 |
# Add this new class for custom stopping criteria
|
9 |
class SentenceEndingCriteria(StoppingCriteria):
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
return last_token in self.end_tokens
|
11 |
|
12 |
def load_model():
|
@@ -23,7 +29,6 @@ def load_model():
|
|
23 |
|
24 |
tokenizer.pad_token = tokenizer.eos_token
|
25 |
|
26 |
-
|
27 |
model = LlamaForCausalLM.from_pretrained(
|
28 |
model_path,
|
29 |
device_map="auto",
|
@@ -43,7 +48,6 @@ def format_chat_history(history):
|
|
43 |
formatted_history += f"<|start_header_id|>assistant<|end_header_id|>{assistant_msg}<|eot_id|>\n"
|
44 |
return formatted_history
|
45 |
|
46 |
-
|
47 |
def chat_response(message, history):
|
48 |
# Format the prompt with system message and chat history
|
49 |
system_prompt = """<|start_header_id|>system<|end_header_id|>You are Fred, a virtual admissions coordinator for Haven Health Management, a mental health and substance abuse treatment facility. Your role is to respond conversationally and empathetically, like a human agent, using 1-2 sentences per response while guiding the conversation effectively. Your primary goal is to understand the caller's reason for reaching out, gather their medical history, and obtain their insurance details, ensuring the conversation feels natural and supportive. Once all the information is gathered politely end the conversation and if the user is qualified tell the user a live agent will reach out soon. Note: Medicaid is not accepted as insurance.<|eot_id|>"""
|
@@ -122,6 +126,5 @@ demo = gr.ChatInterface(
|
|
122 |
]
|
123 |
)
|
124 |
|
125 |
-
|
126 |
if __name__ == "__main__":
|
127 |
-
demo.launch()
|
|
|
7 |
|
8 |
# Add this new class for custom stopping criteria
|
9 |
class SentenceEndingCriteria(StoppingCriteria):
|
10 |
+
def __init__(self, tokenizer, end_tokens):
|
11 |
+
self.tokenizer = tokenizer
|
12 |
+
self.end_tokens = end_tokens
|
13 |
+
|
14 |
+
def __call__(self, input_ids, scores, **kwargs):
|
15 |
+
last_token = input_ids[0][-1]
|
16 |
return last_token in self.end_tokens
|
17 |
|
18 |
def load_model():
|
|
|
29 |
|
30 |
tokenizer.pad_token = tokenizer.eos_token
|
31 |
|
|
|
32 |
model = LlamaForCausalLM.from_pretrained(
|
33 |
model_path,
|
34 |
device_map="auto",
|
|
|
48 |
formatted_history += f"<|start_header_id|>assistant<|end_header_id|>{assistant_msg}<|eot_id|>\n"
|
49 |
return formatted_history
|
50 |
|
|
|
51 |
def chat_response(message, history):
|
52 |
# Format the prompt with system message and chat history
|
53 |
system_prompt = """<|start_header_id|>system<|end_header_id|>You are Fred, a virtual admissions coordinator for Haven Health Management, a mental health and substance abuse treatment facility. Your role is to respond conversationally and empathetically, like a human agent, using 1-2 sentences per response while guiding the conversation effectively. Your primary goal is to understand the caller's reason for reaching out, gather their medical history, and obtain their insurance details, ensuring the conversation feels natural and supportive. Once all the information is gathered politely end the conversation and if the user is qualified tell the user a live agent will reach out soon. Note: Medicaid is not accepted as insurance.<|eot_id|>"""
|
|
|
126 |
]
|
127 |
)
|
128 |
|
|
|
129 |
if __name__ == "__main__":
|
130 |
+
demo.launch() # Remove share=True as it's not needed for HF Spaces
|