mathias1 commited on
Commit
eaeac1f
·
verified ·
1 Parent(s): 629966f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -19
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
- # System and user messages for the chat completion API
10
- system_message = {"role": "system", "content": "You are a helpful assistant, providing health and nutrition advice."}
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
- messages = [
17
- system_message,
18
- health_goals_message,
19
- dietary_preferences_message,
20
- dietary_restrictions_message,
21
- nutritional_interests_message
22
- ]
23
-
24
- # Generating chat completions using the OpenAI API
25
- response = openai.ChatCompletion.create(
26
- model="gpt-3.5-turbo",
27
- messages=messages
28
  )
29
 
30
- return response.choices[0].message['content']
 
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(