Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
from agno.agent import Agent
|
| 4 |
+
from agno.models.nebius import Nebius
|
| 5 |
+
from agno.tools.yfinance import YFinanceTools
|
| 6 |
+
from agno.tools.duckduckgo import DuckDuckGoTools
|
| 7 |
+
import gradio as gr
|
| 8 |
+
|
| 9 |
+
# Load environment variables from .env file
|
| 10 |
+
load_dotenv()
|
| 11 |
+
|
| 12 |
+
# Create the AI finance agent
|
| 13 |
+
agent = Agent(
|
| 14 |
+
name="AI Finance Agent",
|
| 15 |
+
model=Nebius(
|
| 16 |
+
id="meta-llama/Llama-3.3-70B-Instruct",
|
| 17 |
+
api_key=os.getenv("NEBIUS_API_KEY")
|
| 18 |
+
),
|
| 19 |
+
tools=[
|
| 20 |
+
DuckDuckGoTools(),
|
| 21 |
+
YFinanceTools(
|
| 22 |
+
stock_price=True,
|
| 23 |
+
analyst_recommendations=True,
|
| 24 |
+
stock_fundamentals=True
|
| 25 |
+
)
|
| 26 |
+
],
|
| 27 |
+
instructions=[
|
| 28 |
+
"Always use tables to display financial/numerical data.",
|
| 29 |
+
"For text data use bullet points and small paragraphs."
|
| 30 |
+
],
|
| 31 |
+
show_tool_calls=True,
|
| 32 |
+
markdown=True,
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
def respond(user_query: str) -> str:
|
| 36 |
+
"""Run the agent on the user's query and return markdown."""
|
| 37 |
+
try:
|
| 38 |
+
return agent.run(user_query)
|
| 39 |
+
except Exception as e:
|
| 40 |
+
return f"Error: {e}"
|
| 41 |
+
|
| 42 |
+
# Build a Gradio interface
|
| 43 |
+
interface = gr.Interface(
|
| 44 |
+
fn=respond,
|
| 45 |
+
inputs=gr.components.Textbox(lines=2, placeholder="Ask a finance question..."),
|
| 46 |
+
outputs=gr.components.Markdown(),
|
| 47 |
+
title="Finance Agent",
|
| 48 |
+
description="Ask questions about stocks, analyst recommendations, fundamentals and recent news."
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
# If running locally, launch Gradio
|
| 52 |
+
if __name__ == "__main__":
|
| 53 |
+
interface.launch()
|