Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,24 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
from dotenv import load_dotenv
|
| 3 |
import os
|
| 4 |
from langchain.chat_models import ChatOpenAI
|
| 5 |
-
from langchain.agents import initialize_agent, Tool
|
| 6 |
-
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
load_dotenv()
|
| 10 |
api_key = os.getenv("OPENAI_API_KEY")
|
| 11 |
|
| 12 |
-
|
| 13 |
-
st.set_page_config(page_title="π€ Agentic AI Assistant", layout="wide")
|
| 14 |
st.title("π€ Agentic AI Application")
|
| 15 |
-
st.write("Ask me anything
|
| 16 |
|
| 17 |
-
|
| 18 |
-
user_query = st.text_input("π§© Your question or task:", placeholder="e.g., Calculate 45 * 23, or summarize a topic...")
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
|
|
|
| 22 |
llm = ChatOpenAI(openai_api_key=api_key, model="gpt-4o-mini", temperature=0)
|
| 23 |
|
| 24 |
-
# Define tools
|
| 25 |
tools = [
|
| 26 |
-
Tool(
|
| 27 |
-
name="Calculator",
|
| 28 |
-
func=lambda x: str(eval(x)),
|
| 29 |
-
description="Useful for solving math problems."
|
| 30 |
-
),
|
| 31 |
]
|
| 32 |
|
| 33 |
agent = initialize_agent(
|
|
@@ -37,11 +28,7 @@ if api_key:
|
|
| 37 |
verbose=True
|
| 38 |
)
|
| 39 |
|
| 40 |
-
# Run agent on user query
|
| 41 |
if st.button("π Run Agent") and user_query:
|
| 42 |
-
with st.spinner("
|
| 43 |
result = agent.run(user_query)
|
| 44 |
st.success(result)
|
| 45 |
-
|
| 46 |
-
else:
|
| 47 |
-
st.error("β Missing OpenAI API key. Please add it to your .env file.")
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
from langchain.chat_models import ChatOpenAI
|
| 3 |
+
from langchain.agents import initialize_agent, Tool, AgentType
|
| 4 |
+
import streamlit as st
|
| 5 |
|
| 6 |
+
# Get API key from Hugging Face secret
|
|
|
|
| 7 |
api_key = os.getenv("OPENAI_API_KEY")
|
| 8 |
|
| 9 |
+
st.set_page_config(page_title="π€ Agentic AI App", layout="wide")
|
|
|
|
| 10 |
st.title("π€ Agentic AI Application")
|
| 11 |
+
st.write("Ask me anything β I can reason, calculate, or search the web!")
|
| 12 |
|
| 13 |
+
user_query = st.text_input("π§ Your question or task:")
|
|
|
|
| 14 |
|
| 15 |
+
if not api_key:
|
| 16 |
+
st.error("Missing API key! Add OPENAI_API_KEY in Hugging Face β Settings β Secrets.")
|
| 17 |
+
else:
|
| 18 |
llm = ChatOpenAI(openai_api_key=api_key, model="gpt-4o-mini", temperature=0)
|
| 19 |
|
|
|
|
| 20 |
tools = [
|
| 21 |
+
Tool(name="Calculator", func=lambda x: str(eval(x)), description="For math tasks."),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
]
|
| 23 |
|
| 24 |
agent = initialize_agent(
|
|
|
|
| 28 |
verbose=True
|
| 29 |
)
|
| 30 |
|
|
|
|
| 31 |
if st.button("π Run Agent") and user_query:
|
| 32 |
+
with st.spinner("Thinking..."):
|
| 33 |
result = agent.run(user_query)
|
| 34 |
st.success(result)
|
|
|
|
|
|
|
|
|