ha7naa commited on
Commit
d7f3569
·
verified ·
1 Parent(s): 2cdf1bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -5,33 +5,33 @@ import os
5
  client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
6
 
7
  SYSTEM_PROMPT = """You are a professional exercise advisor and fitness coach.
8
- Your goal is to help users improve their physical fitness safely.
9
- Provide beginner-friendly workout advice, warm-up tips, and recovery guidance.
10
- Avoid medical diagnosis and always encourage safe exercise habits."""
11
 
12
  EXAMPLES = """
13
  User: I am a beginner. How should I start exercising?
14
- Assistant: Start with light exercises such as walking, stretching, and bodyweight movements. Aim for 15–20 minutes per session and increase gradually.
15
 
16
  User: How many days per week should I work out?
17
- Assistant: Beginners should exercise 3–4 days per week, allowing rest days for recovery.
18
 
19
  User: What should I do before a workout?
20
- Assistant: Always begin with a warm-up like light cardio and dynamic stretching to prevent injuries.
21
  """
22
 
23
 
 
24
  def respond(message, history, model, temperature, max_tokens):
25
- messages = [{"role": "system", "content": SYSTEM_PROMPT + EXAMPLES}]
26
 
27
-
28
  for h in history:
29
  messages.append({"role": "user", "content": h[0]})
30
  if h[1]:
31
  messages.append({"role": "assistant", "content": h[1]})
32
-
33
  messages.append({"role": "user", "content": message})
34
-
35
  try:
36
  response = client.chat.completions.create(
37
  model=model,
@@ -43,6 +43,7 @@ def respond(message, history, model, temperature, max_tokens):
43
  except Exception as e:
44
  return f"Error: {str(e)}"
45
 
 
46
  # ChatInterface with additional inputs for parameters
47
  demo = gr.ChatInterface(
48
  fn=respond,
 
5
  client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
6
 
7
  SYSTEM_PROMPT = """You are a professional exercise advisor and fitness coach.
8
+ Your goal is to help users improve their physical fitness safely.
9
+ Provide beginner-friendly workout advice, warm-up tips, and recovery guidance.
10
+ Avoid medical diagnosis and always encourage safe exercise habits."""
11
 
12
  EXAMPLES = """
13
  User: I am a beginner. How should I start exercising?
14
+ Assistant: Start with light exercises such as walking, stretching, and bodyweight movements.
15
 
16
  User: How many days per week should I work out?
17
+ Assistant: Beginners should exercise 3–4 days per week.
18
 
19
  User: What should I do before a workout?
20
+ Assistant: Always begin with a warm-up to prevent injuries.
21
  """
22
 
23
 
24
+
25
  def respond(message, history, model, temperature, max_tokens):
26
+ messages = [{"role": "system", "content": SYSTEM_PROMPT + EXAMPLES}]
27
 
 
28
  for h in history:
29
  messages.append({"role": "user", "content": h[0]})
30
  if h[1]:
31
  messages.append({"role": "assistant", "content": h[1]})
32
+
33
  messages.append({"role": "user", "content": message})
34
+
35
  try:
36
  response = client.chat.completions.create(
37
  model=model,
 
43
  except Exception as e:
44
  return f"Error: {str(e)}"
45
 
46
+
47
  # ChatInterface with additional inputs for parameters
48
  demo = gr.ChatInterface(
49
  fn=respond,