Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -15,27 +15,9 @@ initial_prompt = "Hello! I'm an AI chatbot that can help you find the best schoo
|
|
15 |
|
16 |
async def chatbot(child_age, child_grade, child_gender, child_ethnicity, child_talents, desired_location, school_size, school_types, more_options):
|
17 |
"""
|
18 |
-
Chatbot function that
|
19 |
"""
|
20 |
-
|
21 |
-
chat_history.append({"role": "user", "content": initial_prompt})
|
22 |
-
chat_history.append(
|
23 |
-
{"role": "assistant", "content": "What grade is your child in?"})
|
24 |
-
chat_history.append({"role": "user", "content": child_grade})
|
25 |
-
chat_history.append(
|
26 |
-
{"role": "assistant", "content": "What is your child's gender?"})
|
27 |
-
chat_history.append({"role": "user", "content": child_gender})
|
28 |
-
chat_history.append(
|
29 |
-
{"role": "assistant", "content": "What is your child's racial or ethnic background?"})
|
30 |
-
chat_history.append({"role": "user", "content": child_ethnicity})
|
31 |
-
chat_history.append(
|
32 |
-
{"role": "assistant", "content": "Does your child have any special talents or interests, such as sports, arts, or academics?"})
|
33 |
-
chat_history.append({"role": "user", "content": child_talents})
|
34 |
-
chat_history.append(
|
35 |
-
{"role": "assistant", "content": "Where do you currently live?"})
|
36 |
-
chat_history.append({"role": "user", "content": desired_location})
|
37 |
-
|
38 |
-
# Use the Anthropic API to generate school recommendations
|
39 |
user_info = {
|
40 |
"child_age": child_age,
|
41 |
"child_grade": child_grade,
|
@@ -47,33 +29,35 @@ async def chatbot(child_age, child_grade, child_gender, child_ethnicity, child_t
|
|
47 |
"school_types": ", ".join(school_types),
|
48 |
"more_options": ", ".join(more_options),
|
49 |
}
|
50 |
-
|
51 |
user_info_str = "\n".join([f"{k}: {v}" for k, v in user_info.items()])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
response = client.messages.create(
|
53 |
model="claude-3-opus-20240229",
|
54 |
-
max_tokens=
|
55 |
temperature=0.0,
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
Follow these guidelines:
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
3. Always suggest at the bottom of the recommendations that you give, a one-to-one approach or personalized guidance, suggest that they send an email to hello@kiroti-konsult.com.
|
64 |
-
4. Always maintain a friendly, respectful, and professional tone when interacting with users.
|
65 |
|
66 |
-
Remember to focus on providing accurate, relevant, and up-to-date school recommendations that cater to the unique needs and preferences of each user.
|
67 |
-
""",
|
68 |
-
messages=chat_history
|
69 |
-
)
|
70 |
-
print(response)
|
71 |
# Extract recommendations from the response
|
72 |
recommendations = response.content[0].text
|
73 |
-
# if 'content' in response and len(response['content']) > 0 and 'text' in response['content'][0]:
|
74 |
-
# recommendations = response['content'][0]['text']
|
75 |
-
# else:
|
76 |
-
# recommendations = "Sorry, I couldn't find any school recommendations based on your criteria."
|
77 |
|
78 |
return recommendations
|
79 |
|
@@ -105,4 +89,4 @@ chatbot_interface = gr.Interface(
|
|
105 |
)
|
106 |
|
107 |
# Launch the Gradio app
|
108 |
-
chatbot_interface.launch(share=True)
|
|
|
15 |
|
16 |
async def chatbot(child_age, child_grade, child_gender, child_ethnicity, child_talents, desired_location, school_size, school_types, more_options):
|
17 |
"""
|
18 |
+
Chatbot function that generates school recommendations directly.
|
19 |
"""
|
20 |
+
# Create a prompt with user information
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
user_info = {
|
22 |
"child_age": child_age,
|
23 |
"child_grade": child_grade,
|
|
|
29 |
"school_types": ", ".join(school_types),
|
30 |
"more_options": ", ".join(more_options),
|
31 |
}
|
|
|
32 |
user_info_str = "\n".join([f"{k}: {v}" for k, v in user_info.items()])
|
33 |
+
prompt = f"""
|
34 |
+
You are a helpful and knowledgeable AI assistant that specializes in providing school recommendations for children. Based on the following user information, provide at least 8 tailored school recommendations:
|
35 |
+
|
36 |
+
{user_info_str}
|
37 |
+
|
38 |
+
Follow these guidelines:
|
39 |
+
|
40 |
+
1. Provide at least 8 school recommendations that best match the user's criteria. Include relevant details such as school name, location, type, and size.
|
41 |
+
2. Along with the recommendations, provide additional information about each school, including school rating, parent testimonials, and pastoral care.
|
42 |
+
3. Always suggest at the bottom of the recommendations that you give, a one-to-one approach or personalized guidance, suggest that they send an email to hello@kiroti-konsult.com.
|
43 |
+
4. Always maintain a friendly, respectful, and professional tone when interacting with users.
|
44 |
+
|
45 |
+
Remember to focus on providing accurate, relevant, and up-to-date school recommendations that cater to the unique needs and preferences of each user.
|
46 |
+
"""
|
47 |
+
|
48 |
+
# Use the Anthropic API to generate school recommendations
|
49 |
response = client.messages.create(
|
50 |
model="claude-3-opus-20240229",
|
51 |
+
max_tokens=2000,
|
52 |
temperature=0.0,
|
53 |
+
messages=[{"role": "user", "content": prompt}]
|
54 |
+
)
|
|
|
|
|
55 |
|
56 |
+
print("Response object:", response)
|
57 |
+
print("Type of response object:", type(response))
|
|
|
|
|
58 |
|
|
|
|
|
|
|
|
|
|
|
59 |
# Extract recommendations from the response
|
60 |
recommendations = response.content[0].text
|
|
|
|
|
|
|
|
|
61 |
|
62 |
return recommendations
|
63 |
|
|
|
89 |
)
|
90 |
|
91 |
# Launch the Gradio app
|
92 |
+
chatbot_interface.launch(share=True)
|