File size: 1,479 Bytes
4412350
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
from dotenv import load_dotenv
from agno.agent import Agent
from agno.models.nebius import Nebius
from agno.tools.yfinance import YFinanceTools
from agno.tools.duckduckgo import DuckDuckGoTools
import gradio as gr

# Load environment variables from .env file
load_dotenv()

# Create the AI finance agent
agent = Agent(
    name="AI Finance Agent",
    model=Nebius(
        id="meta-llama/Llama-3.3-70B-Instruct",
        api_key=os.getenv("NEBIUS_API_KEY")
    ),
    tools=[
        DuckDuckGoTools(),
        YFinanceTools(
            stock_price=True,
            analyst_recommendations=True,
            stock_fundamentals=True
        )
    ],
    instructions=[
        "Always use tables to display financial/numerical data.",
        "For text data use bullet points and small paragraphs."
    ],
    show_tool_calls=True,
    markdown=True,
)

def respond(user_query: str) -> str:
    """Run the agent on the user's query and return markdown."""
    try:
        return agent.run(user_query)
    except Exception as e:
        return f"Error: {e}"

# Build a Gradio interface
interface = gr.Interface(
    fn=respond,
    inputs=gr.components.Textbox(lines=2, placeholder="Ask a finance question..."),
    outputs=gr.components.Markdown(),
    title="Finance Agent",
    description="Ask questions about stocks, analyst recommendations, fundamentals and recent news."
)

# If running locally, launch Gradio
if __name__ == "__main__":
    interface.launch()