Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import streamlit as st
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
-
from
|
| 5 |
from phi.model.groq import Groq
|
| 6 |
from phi.tools.duckduckgo import DuckDuckGo
|
| 7 |
from phi.tools.yfinance import YFinanceTools
|
|
@@ -13,12 +13,16 @@ load_dotenv()
|
|
| 13 |
deepseek_api_key = os.getenv("GROQ_DEEPSEEK_API_KEY")
|
| 14 |
qwen_api_key = os.getenv("GROQ_QWEN_API_KEY")
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
# Debugging API key loading
|
| 17 |
if not deepseek_api_key or not qwen_api_key:
|
| 18 |
-
st.error("Missing API keys.
|
| 19 |
st.stop()
|
| 20 |
|
| 21 |
-
# Define Web Agent
|
| 22 |
web_agent = Agent(
|
| 23 |
name="Web Agent",
|
| 24 |
model=Groq(id="qwen-2.5-coder-32b", api_key=qwen_api_key),
|
|
@@ -28,7 +32,7 @@ web_agent = Agent(
|
|
| 28 |
markdown=True,
|
| 29 |
)
|
| 30 |
|
| 31 |
-
# Define Finance Agent
|
| 32 |
finance_agent = Agent(
|
| 33 |
name="Finance Agent",
|
| 34 |
role="Get financial data",
|
|
@@ -39,7 +43,7 @@ finance_agent = Agent(
|
|
| 39 |
markdown=True,
|
| 40 |
)
|
| 41 |
|
| 42 |
-
#
|
| 43 |
agent_team = Agent(
|
| 44 |
model=Groq(id="deepseek-r1-distill-llama-70b", api_key=deepseek_api_key),
|
| 45 |
team=[web_agent, finance_agent],
|
|
@@ -48,29 +52,13 @@ agent_team = Agent(
|
|
| 48 |
markdown=True,
|
| 49 |
)
|
| 50 |
|
| 51 |
-
# Streamlit UI
|
| 52 |
-
st.set_page_config(page_title="AI Chat Assistant", layout="wide")
|
| 53 |
-
st.title("🤖 AI Chat Assistant")
|
| 54 |
-
|
| 55 |
# User input
|
| 56 |
-
|
| 57 |
-
with st.chat_message("user"):
|
| 58 |
-
st.markdown(prompt)
|
| 59 |
-
|
| 60 |
-
with st.chat_message("assistant"):
|
| 61 |
-
response_container = st.empty()
|
| 62 |
-
response_text = ""
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
st.error(error_message)
|
| 72 |
-
response_text = error_message
|
| 73 |
-
else:
|
| 74 |
-
error_message = "Error: Agent does not support responses."
|
| 75 |
-
st.error(error_message)
|
| 76 |
-
response_text = error_message
|
|
|
|
| 1 |
import os
|
| 2 |
import streamlit as st
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
+
from phi.agent import Agent
|
| 5 |
from phi.model.groq import Groq
|
| 6 |
from phi.tools.duckduckgo import DuckDuckGo
|
| 7 |
from phi.tools.yfinance import YFinanceTools
|
|
|
|
| 13 |
deepseek_api_key = os.getenv("GROQ_DEEPSEEK_API_KEY")
|
| 14 |
qwen_api_key = os.getenv("GROQ_QWEN_API_KEY")
|
| 15 |
|
| 16 |
+
# Streamlit UI setup
|
| 17 |
+
st.set_page_config(page_title="AI Agent Hub", layout="wide")
|
| 18 |
+
st.title("🤖 AI Agent Hub")
|
| 19 |
+
|
| 20 |
# Debugging API key loading
|
| 21 |
if not deepseek_api_key or not qwen_api_key:
|
| 22 |
+
st.error("Missing API keys. Ensure they are set in the Hugging Face Secrets.")
|
| 23 |
st.stop()
|
| 24 |
|
| 25 |
+
# Define the Web Agent using Groq's QWEN model
|
| 26 |
web_agent = Agent(
|
| 27 |
name="Web Agent",
|
| 28 |
model=Groq(id="qwen-2.5-coder-32b", api_key=qwen_api_key),
|
|
|
|
| 32 |
markdown=True,
|
| 33 |
)
|
| 34 |
|
| 35 |
+
# Define the Finance Agent using Groq's DeepSeek model
|
| 36 |
finance_agent = Agent(
|
| 37 |
name="Finance Agent",
|
| 38 |
role="Get financial data",
|
|
|
|
| 43 |
markdown=True,
|
| 44 |
)
|
| 45 |
|
| 46 |
+
# Combine agents into a team
|
| 47 |
agent_team = Agent(
|
| 48 |
model=Groq(id="deepseek-r1-distill-llama-70b", api_key=deepseek_api_key),
|
| 49 |
team=[web_agent, finance_agent],
|
|
|
|
| 52 |
markdown=True,
|
| 53 |
)
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
# User input
|
| 56 |
+
query = st.text_input("Enter your query:")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
if query:
|
| 59 |
+
with st.spinner("Fetching results..."):
|
| 60 |
+
try:
|
| 61 |
+
response = agent_team.respond(query)
|
| 62 |
+
st.write(response)
|
| 63 |
+
except Exception as e:
|
| 64 |
+
st.error(f"Error: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|