Spaces:
No application file
No application file
| 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) | |