1.i followed all the instructions but still i am getting the same error
this is the code(main):
from boltiotai import openai
from flask import Flask, render_template_string, request
import openai
import os
Helper function to generate health advice
def generate_health_advice(messages):
openai.api_key = os.environ.get(“API_KEY_o”)
if not openai.api_key:
return “You have not set the OpenAI API key.”
response = openai.chat.completions.create(model="gpt-3.5-turbo",
messages=messages)
if not response.choices or len(response.choices) == 0:
return "Sorry, unable to provide health advice at the moment. Please try again later."
output = response.choices[0].message.content
return output
Create a Flask web application object named app
app = Flask(name)
Initialize messages
messages = [{
“role”:
“system”,
“content”:
“You are a helpful assistant providing health-related advice. You need to interactively assist users with either diet plans or illness information based on their input.”
}]
@app.route(‘/’, methods=[‘GET’, ‘POST’])
def home():
global messages
user_input = “”
response = “”
if request.method == 'POST':
user_input = request.form['query']
messages.append({"role": "user", "content": user_input})
if user_input.lower() == 'd':
response = "Please provide your age, gender, weight, and height separated by commas (e.g., 25, male, 70kg, 175cm):"
elif user_input.lower() == 'i':
response = "What disease can I help with?"
else:
# Handle inputs for age, gender, weight, height for diet or disease details
last_message = messages[-2]['content']
if last_message.startswith("Please provide your age"):
age, gender, weight, height = [
x.strip() for x in user_input.split(',')
]
messages.append({
"role":
"user",
"content":
f"Age: {age}, Gender: {gender}, Weight: {weight}, Height: {height}"
})
user_input = f"I need a diet plan for a {gender} aged {age} with a weight of {weight} and height of {height}."
elif last_message == "What disease can I help with?":
messages.append({
"role": "user",
"content": f"Disease: {user_input}"
})
response = generate_health_advice(messages)
messages.append({"role": "assistant", "content": response})
return render_template_string('''<!DOCTYPE html>
Personal Health Assistant
YOUR PERSONAL HEALTH ASSISTANT
{% for message in messages %}
{% if message.role == 'user' %}
You:
{{ message.content }}
{% else %}
Assistant:
{{ message.content }}
{% endif %}
{% endfor %}
How may I help you?:
Submit
''',
messages=messages)
Start the Flask application if the script is being run directly
if name == ‘main’:
app.run(host=‘0.0.0.0’, port=8080, debug=True)
this is the css file:body {
font-family: Arial, sans-serif;
background: url(“…/images/image.jpg”) no-repeat center center fixed;
background-size: cover;
margin: 0;
padding: 0;
color: #ffffff;
}
.container {
max-width: 800px;
margin: 50px auto;
padding: 20px;
background: rgba(0, 0, 0, 0.7);
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}
h1 {
text-align: center;
color: #ffffff;
}
form {
background: rgba(255, 255, 255, 0.1);
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.form-label {
font-weight: bold;
color: #ffffff;
}
.form-control {
width: 100%;
padding: 10px;
margin-bottom: 10px;
border-radius: 4px;
border: 1px solid #ffffff;
background: rgba(255, 255, 255, 0.2);
color: #ffffff;
}
.form-control::placeholder {
color: #cccccc;
}
.btn {
display: inline-block;
font-weight: 400;
color: #ffffff;
text-align: center;
vertical-align: middle;
user-select: none;
background-color: #007bff;
border: 1px solid #007bff;
padding: 10px 20px;
font-size: 16px;
line-height: 1.5;
border-radius: 4px;
transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
.btn-primary:hover {
background-color: #0056b3;
border-color: #004085;
}
.chat-box {
margin-top: 20px;
background: rgba(255, 255, 255, 0.1);
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
padding: 20px;
}
.user-query, .assistant-response {
display: flex;
flex-direction: column;
margin-bottom: 10px;
}
.user-label, .assistant-label {
font-weight: bold;
color: #00ffcc;
}
.user-text, .assistant-text {
background: rgba(255, 255, 255, 0.2);
padding: 10px;
border-radius: 4px;
border: 1px solid #ffffff;
color: #ffffff;
}
PLEASE KINDLY HELP WITH THIS