Aadarshwahmare commited on
Commit
e184596
·
verified ·
1 Parent(s): 3160578

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -2,15 +2,21 @@ import gradio as gr
2
  import google.generativeai as genai
3
  import os
4
 
5
- # Configure API key
6
- genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
 
 
 
 
 
 
 
7
 
8
- model = genai.GenerativeModel("gemini-1.5-flash")
9
 
10
  def fitness_coach(age, weight, goal, activity):
11
  try:
12
  prompt = f"""
13
- You are a certified fitness coach and nutrition expert.
14
 
15
  Create a personalized fitness plan:
16
 
@@ -26,18 +32,20 @@ def fitness_coach(age, weight, goal, activity):
26
  """
27
 
28
  response = model.generate_content(prompt)
29
- return response.text
 
30
 
31
  except Exception as e:
32
  return f"Error: {str(e)}"
33
 
 
34
  interface = gr.Interface(
35
  fn=fitness_coach,
36
  inputs=[
37
  gr.Number(label="Age"),
38
  gr.Number(label="Weight (kg)"),
39
  gr.Dropdown(["Weight Loss", "Muscle Gain", "Maintenance"], label="Goal"),
40
- gr.Dropdown(["Beginner", "Intermediate", "Advanced"], label="Activity Level")
41
  ],
42
  outputs="text",
43
  title="💪 Personalized Fitness Coach",
 
2
  import google.generativeai as genai
3
  import os
4
 
5
+ # Get API key
6
+ api_key = os.getenv("GOOGLE_API_KEY")
7
+
8
+ if not api_key:
9
+ raise ValueError("API key missing")
10
+
11
+ genai.configure(api_key=api_key)
12
+
13
+ model = genai.GenerativeModel("gemini-pro")
14
 
 
15
 
16
  def fitness_coach(age, weight, goal, activity):
17
  try:
18
  prompt = f"""
19
+ You are a certified fitness coach.
20
 
21
  Create a personalized fitness plan:
22
 
 
32
  """
33
 
34
  response = model.generate_content(prompt)
35
+
36
+ return response.text if response.text else "No response generated"
37
 
38
  except Exception as e:
39
  return f"Error: {str(e)}"
40
 
41
+
42
  interface = gr.Interface(
43
  fn=fitness_coach,
44
  inputs=[
45
  gr.Number(label="Age"),
46
  gr.Number(label="Weight (kg)"),
47
  gr.Dropdown(["Weight Loss", "Muscle Gain", "Maintenance"], label="Goal"),
48
+ gr.Dropdown(["Beginner", "Intermediate", "Advanced"], label="Activity Level"),
49
  ],
50
  outputs="text",
51
  title="💪 Personalized Fitness Coach",