Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,28 +6,22 @@ import gradio as gr
|
|
| 6 |
openai.api_key = os.getenv('OPENAI_API_KEY')
|
| 7 |
|
| 8 |
def generate_health_advice(health_goals, dietary_preferences, dietary_restrictions, nutritional_interests):
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
health_goals_message = {"role": "user", "content": f"My health goals are: {health_goals}."}
|
| 12 |
-
dietary_preferences_message = {"role": "user", "content": f"My dietary preferences are: {dietary_preferences}."}
|
| 13 |
-
dietary_restrictions_message = {"role": "user", "content": f"I have the following dietary restrictions: {dietary_restrictions}."}
|
| 14 |
-
nutritional_interests_message = {"role": "user", "content": f"I'm interested in learning more about: {nutritional_interests}."}
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
response = openai.ChatCompletion.create(
|
| 26 |
-
model="gpt-3.5-turbo",
|
| 27 |
-
messages=messages
|
| 28 |
)
|
| 29 |
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
# Gradio interface setup
|
| 33 |
iface = gr.Interface(
|
|
|
|
| 6 |
openai.api_key = os.getenv('OPENAI_API_KEY')
|
| 7 |
|
| 8 |
def generate_health_advice(health_goals, dietary_preferences, dietary_restrictions, nutritional_interests):
|
| 9 |
+
# Construct the prompt
|
| 10 |
+
prompt = f"You are a helpful assistant, providing health and nutrition advice.\nMy health goals are: {health_goals}.\nMy dietary preferences are: {dietary_preferences}.\nI have the following dietary restrictions: {dietary_restrictions}.\nI'm interested in learning more about: {nutritional_interests}."
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
# Generate the response using the OpenAI Completion API
|
| 13 |
+
response = openai.Completion.create(
|
| 14 |
+
model="text-davinci-003", # Adjust model as necessary
|
| 15 |
+
prompt=prompt,
|
| 16 |
+
temperature=0.5,
|
| 17 |
+
max_tokens=150,
|
| 18 |
+
top_p=1.0,
|
| 19 |
+
frequency_penalty=0.0,
|
| 20 |
+
presence_penalty=0.0
|
|
|
|
|
|
|
|
|
|
| 21 |
)
|
| 22 |
|
| 23 |
+
# Return the text of the first choice
|
| 24 |
+
return response.choices[0].text.strip()
|
| 25 |
|
| 26 |
# Gradio interface setup
|
| 27 |
iface = gr.Interface(
|