Spaces:
Running
Running
Update app.py
Browse filesFinal fix - working model
app.py
CHANGED
|
@@ -5,61 +5,41 @@ import os
|
|
| 5 |
# Configure API key
|
| 6 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 7 |
|
| 8 |
-
# Use
|
| 9 |
-
model = genai.GenerativeModel("gemini-
|
| 10 |
|
| 11 |
def fitness_coach(age, weight, goal, activity):
|
| 12 |
try:
|
| 13 |
prompt = f"""
|
| 14 |
-
You are a
|
| 15 |
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
Activity Level: {activity}
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
- If Intermediate β moderate plan
|
| 30 |
-
- If Advanced β intense plan
|
| 31 |
-
|
| 32 |
-
Include:
|
| 33 |
-
1. Workout Plan
|
| 34 |
-
2. Diet Plan
|
| 35 |
-
3. Tips
|
| 36 |
-
|
| 37 |
-
Make sure the response changes based on inputs.
|
| 38 |
-
"""
|
| 39 |
-
|
| 40 |
-
response = model.generate_content(
|
| 41 |
-
prompt,
|
| 42 |
-
generation_config={
|
| 43 |
-
"temperature": 0.9,
|
| 44 |
-
"top_p": 1,
|
| 45 |
-
"top_k": 1,
|
| 46 |
-
"max_output_tokens": 500,
|
| 47 |
-
}
|
| 48 |
-
)
|
| 49 |
|
|
|
|
| 50 |
return response.text
|
| 51 |
|
| 52 |
except Exception as e:
|
| 53 |
return f"Error: {str(e)}"
|
| 54 |
|
| 55 |
-
|
| 56 |
interface = gr.Interface(
|
| 57 |
fn=fitness_coach,
|
| 58 |
inputs=[
|
| 59 |
gr.Number(label="Age"),
|
| 60 |
gr.Number(label="Weight (kg)"),
|
| 61 |
gr.Dropdown(["Weight Loss", "Muscle Gain", "Maintenance"], label="Goal"),
|
| 62 |
-
gr.Dropdown(["Beginner", "Intermediate", "Advanced"], label="Activity Level")
|
| 63 |
],
|
| 64 |
outputs="text",
|
| 65 |
title="πͺ Personalized Fitness Coach",
|
|
|
|
| 5 |
# Configure API key
|
| 6 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 7 |
|
| 8 |
+
# Use working model
|
| 9 |
+
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 10 |
|
| 11 |
def fitness_coach(age, weight, goal, activity):
|
| 12 |
try:
|
| 13 |
prompt = f"""
|
| 14 |
+
You are a certified fitness coach.
|
| 15 |
|
| 16 |
+
Create a personalized fitness plan:
|
| 17 |
|
| 18 |
+
Age: {age}
|
| 19 |
+
Weight: {weight}
|
| 20 |
+
Goal: {goal}
|
| 21 |
+
Activity Level: {activity}
|
|
|
|
| 22 |
|
| 23 |
+
Include:
|
| 24 |
+
1. Workout Plan
|
| 25 |
+
2. Diet Plan
|
| 26 |
+
3. Tips
|
| 27 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
response = model.generate_content(prompt)
|
| 30 |
return response.text
|
| 31 |
|
| 32 |
except Exception as e:
|
| 33 |
return f"Error: {str(e)}"
|
| 34 |
|
| 35 |
+
|
| 36 |
interface = gr.Interface(
|
| 37 |
fn=fitness_coach,
|
| 38 |
inputs=[
|
| 39 |
gr.Number(label="Age"),
|
| 40 |
gr.Number(label="Weight (kg)"),
|
| 41 |
gr.Dropdown(["Weight Loss", "Muscle Gain", "Maintenance"], label="Goal"),
|
| 42 |
+
gr.Dropdown(["Beginner", "Intermediate", "Advanced"], label="Activity Level"),
|
| 43 |
],
|
| 44 |
outputs="text",
|
| 45 |
title="πͺ Personalized Fitness Coach",
|