File size: 1,095 Bytes
d842a82
 
23764bd
 
d842a82
23764bd
d842a82
 
23764bd
d842a82
23764bd
d842a82
23764bd
d842a82
23764bd
 
 
d842a82
 
 
23764bd
d842a82
 
 
 
 
 
 
 
 
 
23764bd
d842a82
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
from langchain.chat_models import ChatOpenAI
from langchain.agents import initialize_agent, Tool, AgentType
import streamlit as st

# Get API key from Hugging Face secret
api_key = os.getenv("OPENAI_API_KEY")

st.set_page_config(page_title="πŸ€– Agentic AI App", layout="wide")
st.title("πŸ€– Agentic AI Application")
st.write("Ask me anything β€” I can reason, calculate, or search the web!")

user_query = st.text_input("🧠 Your question or task:")

if not api_key:
    st.error("Missing API key! Add OPENAI_API_KEY in Hugging Face β†’ Settings β†’ Secrets.")
else:
    llm = ChatOpenAI(openai_api_key=api_key, model="gpt-4o-mini", temperature=0)

    tools = [
        Tool(name="Calculator", func=lambda x: str(eval(x)), description="For math tasks."),
    ]

    agent = initialize_agent(
        tools=tools,
        llm=llm,
        agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
        verbose=True
    )

    if st.button("πŸš€ Run Agent") and user_query:
        with st.spinner("Thinking..."):
            result = agent.run(user_query)
            st.success(result)