Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
from langchain.agents import initialize_agent, Tool
|
| 4 |
+
from langchain.agents.agent_types import AgentType
|
| 5 |
+
from langchain_community.llms.groq import ChatGroq
|
| 6 |
+
from dotenv import load_dotenv
|
| 7 |
+
|
| 8 |
+
# Load .env
|
| 9 |
+
load_dotenv()
|
| 10 |
+
|
| 11 |
+
# --- Groq API Key ---
|
| 12 |
+
GROQ_API_KEY = os.getenv("GROQ_API_KEY") or st.secrets.get("GROQ_API_KEY", "")
|
| 13 |
+
if not GROQ_API_KEY:
|
| 14 |
+
st.error("❌ Please set your GROQ_API_KEY in Hugging Face Secrets.")
|
| 15 |
+
st.stop()
|
| 16 |
+
|
| 17 |
+
# --- LLM Setup ---
|
| 18 |
+
llm = ChatGroq(api_key=GROQ_API_KEY, model_name="mixtral-8x7b-32768")
|
| 19 |
+
|
| 20 |
+
# --- Define a goal breakdown function (not lambda) ---
|
| 21 |
+
def goal_planner_tool(user_goal: str) -> str:
|
| 22 |
+
return f"4-Week Goal: {user_goal}\n\n" \
|
| 23 |
+
f"Week 1: Research and outline\n" \
|
| 24 |
+
f"Week 2: Start execution with small tasks\n" \
|
| 25 |
+
f"Week 3: Iterate, improve, and scale\n" \
|
| 26 |
+
f"Week 4: Final review, wrap-up, and reflect\n\n" \
|
| 27 |
+
f"Tip: Stay consistent and track your progress daily."
|
| 28 |
+
|
| 29 |
+
# --- Tools ---
|
| 30 |
+
tools = [
|
| 31 |
+
Tool(
|
| 32 |
+
name="GoalPlanner",
|
| 33 |
+
func=goal_planner_tool,
|
| 34 |
+
description="Breaks a 4-week goal into weekly action steps."
|
| 35 |
+
)
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
# --- Initialize Agent ---
|
| 39 |
+
agent = initialize_agent(
|
| 40 |
+
tools,
|
| 41 |
+
llm,
|
| 42 |
+
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
| 43 |
+
verbose=False
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
# --- Streamlit App UI ---
|
| 47 |
+
st.set_page_config(page_title="Goal Planner Buddy", layout="centered")
|
| 48 |
+
|
| 49 |
+
# --- Custom dark mode styling ---
|
| 50 |
+
custom_css = """
|
| 51 |
+
<style>
|
| 52 |
+
.stApp {
|
| 53 |
+
background-color: #121212;
|
| 54 |
+
color: white;
|
| 55 |
+
}
|
| 56 |
+
input, textarea {
|
| 57 |
+
background-color: #1e1e1e !important;
|
| 58 |
+
color: white !important;
|
| 59 |
+
}
|
| 60 |
+
.stButton > button {
|
| 61 |
+
background-color: #4CAF50;
|
| 62 |
+
color: white;
|
| 63 |
+
}
|
| 64 |
+
</style>
|
| 65 |
+
"""
|
| 66 |
+
st.markdown(custom_css, unsafe_allow_html=True)
|
| 67 |
+
|
| 68 |
+
# --- UI ---
|
| 69 |
+
st.title("🎯 Goal Planner Buddy")
|
| 70 |
+
st.subheader("Break your goals into weekly plans with AI")
|
| 71 |
+
|
| 72 |
+
goal_input = st.text_input("Enter your 4-week goal:")
|
| 73 |
+
if st.button("Generate Plan"):
|
| 74 |
+
if goal_input:
|
| 75 |
+
try:
|
| 76 |
+
prompt = f"Break down this 4-week goal into weekly tasks and motivation tips: {goal_input}"
|
| 77 |
+
response = agent.run(prompt)
|
| 78 |
+
st.success("✅ Plan Generated:")
|
| 79 |
+
st.markdown(f"```\n{response}\n```")
|
| 80 |
+
except Exception as e:
|
| 81 |
+
st.error(f"⚠️ Agent error: {e}")
|
| 82 |
+
else:
|
| 83 |
+
st.warning("Please enter a goal.")
|