Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from datetime import datetime
|
| 3 |
from prompt_builder import build_prompt
|
| 4 |
-
from model_api import query_model, test_api_connection
|
| 5 |
|
| 6 |
st.set_page_config(
|
| 7 |
page_title="FIT Plan AI - Milestone 2",
|
|
@@ -36,7 +36,7 @@ if "api_status" not in st.session_state:
|
|
| 36 |
st.session_state.api_status = api_ok
|
| 37 |
st.session_state.api_message = api_message
|
| 38 |
|
| 39 |
-
# Show API status in sidebar
|
| 40 |
with st.sidebar:
|
| 41 |
st.header("π§ System Status")
|
| 42 |
if st.session_state.get("api_status", False):
|
|
@@ -44,6 +44,45 @@ with st.sidebar:
|
|
| 44 |
else:
|
| 45 |
st.error(f"β API Error: {st.session_state.get('api_message', 'Unknown error')}")
|
| 46 |
st.info("Please set your HF_TOKEN environment variable")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
# Initialize session state
|
| 49 |
if "form_submitted" not in st.session_state:
|
|
@@ -203,7 +242,7 @@ with tab2:
|
|
| 203 |
else:
|
| 204 |
# Check API status
|
| 205 |
if not st.session_state.get("api_status", False):
|
| 206 |
-
st.error("β οΈ API is not connected. Please check your HF_TOKEN environment variable.")
|
| 207 |
st.stop()
|
| 208 |
|
| 209 |
# Show profile summary
|
|
@@ -223,7 +262,7 @@ with tab2:
|
|
| 223 |
col1, col2, col3 = st.columns([1, 2, 1])
|
| 224 |
with col2:
|
| 225 |
if st.button("π Generate Workout Plan", type="primary", use_container_width=True):
|
| 226 |
-
with st.spinner("Creating your personalized workout plan... This may take a moment."):
|
| 227 |
# Call the model API from model_api.py
|
| 228 |
workout_plan = query_model(st.session_state.prompt)
|
| 229 |
st.session_state.workout_plan = workout_plan
|
|
@@ -234,12 +273,12 @@ with tab2:
|
|
| 234 |
st.markdown("---")
|
| 235 |
st.subheader("π Your 5-Day Workout Plan")
|
| 236 |
|
| 237 |
-
# Check if plan is complete
|
| 238 |
is_complete, message = verify_workout_plan(st.session_state.workout_plan)
|
| 239 |
if not is_complete:
|
| 240 |
st.warning(f"β οΈ {message}. You can regenerate the plan if needed.")
|
| 241 |
|
| 242 |
-
# Display the workout plan
|
| 243 |
with st.container():
|
| 244 |
st.markdown(st.session_state.workout_plan)
|
| 245 |
|
|
@@ -254,6 +293,7 @@ with tab2:
|
|
| 254 |
FIT PLAN AI - PERSONALIZED WORKOUT PLAN
|
| 255 |
Generated for: {st.session_state.name}
|
| 256 |
Date: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
|
|
|
|
| 257 |
|
| 258 |
PROFILE SUMMARY:
|
| 259 |
- Age: {st.session_state.age}
|
|
@@ -279,7 +319,7 @@ Generated by FIT Plan AI
|
|
| 279 |
|
| 280 |
with col2:
|
| 281 |
if st.button("π Regenerate Plan", use_container_width=True):
|
| 282 |
-
with st.spinner("Regenerating your workout plan..."):
|
| 283 |
workout_plan = query_model(st.session_state.prompt)
|
| 284 |
st.session_state.workout_plan = workout_plan
|
| 285 |
st.rerun()
|
|
@@ -309,4 +349,4 @@ Generated by FIT Plan AI
|
|
| 309 |
|
| 310 |
# Footer
|
| 311 |
st.markdown("---")
|
| 312 |
-
st.caption("FIT Plan AI - Milestone 2 | Powered by
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from datetime import datetime
|
| 3 |
from prompt_builder import build_prompt
|
| 4 |
+
from model_api import query_model, test_api_connection, switch_model, set_ollama_mode
|
| 5 |
|
| 6 |
st.set_page_config(
|
| 7 |
page_title="FIT Plan AI - Milestone 2",
|
|
|
|
| 36 |
st.session_state.api_status = api_ok
|
| 37 |
st.session_state.api_message = api_message
|
| 38 |
|
| 39 |
+
# Show API status and model settings in sidebar
|
| 40 |
with st.sidebar:
|
| 41 |
st.header("π§ System Status")
|
| 42 |
if st.session_state.get("api_status", False):
|
|
|
|
| 44 |
else:
|
| 45 |
st.error(f"β API Error: {st.session_state.get('api_message', 'Unknown error')}")
|
| 46 |
st.info("Please set your HF_TOKEN environment variable")
|
| 47 |
+
|
| 48 |
+
# Add model selection
|
| 49 |
+
st.markdown("---")
|
| 50 |
+
st.header("π€ Model Settings")
|
| 51 |
+
|
| 52 |
+
# Model selection dropdown
|
| 53 |
+
model_options = {
|
| 54 |
+
"Llama 3.2 3B (Recommended)": "meta-llama/Llama-3.2-3B-Instruct",
|
| 55 |
+
"Llama 3.2 1B (Lightweight)": "meta-llama/Llama-3.2-1B-Instruct",
|
| 56 |
+
"Llama 3.3 70B (Best Quality)": "meta-llama/Llama-3.3-70B-Instruct",
|
| 57 |
+
"Fitness Assistant (Specialized)": "Soorya03/Llama-3.2-1B-FitnessAssistant",
|
| 58 |
+
"Mistral-7B (Original)": "mistralai/Mistral-7B-Instruct-v0.2"
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
selected_model = st.selectbox(
|
| 62 |
+
"Select Model",
|
| 63 |
+
options=list(model_options.keys()),
|
| 64 |
+
index=0
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
# Mode selection (API vs Local)
|
| 68 |
+
use_ollama = st.checkbox("Use Local Ollama (No API key needed)", value=False)
|
| 69 |
+
|
| 70 |
+
if st.button("Apply Settings"):
|
| 71 |
+
switch_model(model_options[selected_model])
|
| 72 |
+
set_ollama_mode(use_ollama)
|
| 73 |
+
# Retest connection with new settings
|
| 74 |
+
api_ok, api_message = test_api_connection()
|
| 75 |
+
st.session_state.api_status = api_ok
|
| 76 |
+
st.session_state.api_message = api_message
|
| 77 |
+
st.success(f"Switched to {selected_model}")
|
| 78 |
+
st.rerun()
|
| 79 |
+
|
| 80 |
+
if use_ollama:
|
| 81 |
+
st.info("π Make sure Ollama is running locally: 'ollama run llama3.2:3b'")
|
| 82 |
+
|
| 83 |
+
# Show current model info
|
| 84 |
+
st.markdown("---")
|
| 85 |
+
st.caption(f"Current: {selected_model}")
|
| 86 |
|
| 87 |
# Initialize session state
|
| 88 |
if "form_submitted" not in st.session_state:
|
|
|
|
| 242 |
else:
|
| 243 |
# Check API status
|
| 244 |
if not st.session_state.get("api_status", False):
|
| 245 |
+
st.error("β οΈ API is not connected. Please check your HF_TOKEN environment variable or use local Ollama.")
|
| 246 |
st.stop()
|
| 247 |
|
| 248 |
# Show profile summary
|
|
|
|
| 262 |
col1, col2, col3 = st.columns([1, 2, 1])
|
| 263 |
with col2:
|
| 264 |
if st.button("π Generate Workout Plan", type="primary", use_container_width=True):
|
| 265 |
+
with st.spinner("Creating your personalized workout plan with Llama... This may take a moment."):
|
| 266 |
# Call the model API from model_api.py
|
| 267 |
workout_plan = query_model(st.session_state.prompt)
|
| 268 |
st.session_state.workout_plan = workout_plan
|
|
|
|
| 273 |
st.markdown("---")
|
| 274 |
st.subheader("π Your 5-Day Workout Plan")
|
| 275 |
|
| 276 |
+
# Check if plan is complete
|
| 277 |
is_complete, message = verify_workout_plan(st.session_state.workout_plan)
|
| 278 |
if not is_complete:
|
| 279 |
st.warning(f"β οΈ {message}. You can regenerate the plan if needed.")
|
| 280 |
|
| 281 |
+
# Display the workout plan in a nice container
|
| 282 |
with st.container():
|
| 283 |
st.markdown(st.session_state.workout_plan)
|
| 284 |
|
|
|
|
| 293 |
FIT PLAN AI - PERSONALIZED WORKOUT PLAN
|
| 294 |
Generated for: {st.session_state.name}
|
| 295 |
Date: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
|
| 296 |
+
Model: {selected_model}
|
| 297 |
|
| 298 |
PROFILE SUMMARY:
|
| 299 |
- Age: {st.session_state.age}
|
|
|
|
| 319 |
|
| 320 |
with col2:
|
| 321 |
if st.button("π Regenerate Plan", use_container_width=True):
|
| 322 |
+
with st.spinner("Regenerating your workout plan with Llama..."):
|
| 323 |
workout_plan = query_model(st.session_state.prompt)
|
| 324 |
st.session_state.workout_plan = workout_plan
|
| 325 |
st.rerun()
|
|
|
|
| 349 |
|
| 350 |
# Footer
|
| 351 |
st.markdown("---")
|
| 352 |
+
st.caption("FIT Plan AI - Milestone 2 | Powered by Llama Models")
|