JC321 commited on
Commit
e1d1165
·
verified ·
1 Parent(s): 88d78b9

Upload 2 files

Browse files
Files changed (2) hide show
  1. README.md +70 -10
  2. app.py +19 -46
README.md CHANGED
@@ -12,28 +12,88 @@ license: mit
12
 
13
  # SEC Financial Data Query Assistant
14
 
15
- A Gradio-based web application for querying SEC financial data through MCP Server.
16
 
17
- ## Features
18
 
 
 
19
  - 🔍 Search companies by name or ticker symbol
20
  - 📈 View latest financial data
21
  - 📊 Analyze 3-year and 5-year financial trends
22
  - 💰 Display revenue, net income, EPS, operating expenses, and cash flow metrics
 
23
 
24
- ## Usage
25
 
26
- Simply enter a company name or ticker symbol (e.g., NVIDIA, AAPL, Microsoft) and select the query type:
27
- - **Latest Financial Data**: Shows the most recent fiscal year data
28
- - **3-Year Trend**: Displays financial trends over 3 years
29
- - **5-Year Trend**: Displays financial trends over 5 years
30
 
31
- ## Data Source
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  SEC EDGAR data via MCP Server: https://huggingface.co/spaces/JC321/EasyReportDateMCP
34
 
35
- ## Technology Stack
36
 
37
- - **Frontend**: Gradio 4.0+
38
  - **Backend**: Python with requests
 
 
39
  - **Data Source**: SEC EDGAR via MCP Server
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  # SEC Financial Data Query Assistant
14
 
15
+ A Gradio-based AI-powered web application for querying SEC financial data through MCP Server.
16
 
17
+ ## Features
18
 
19
+ - 🤖 **Intelligent AI Assistant**: Chat naturally with Qwen/Qwen2.5-72B-Instruct model
20
+ - 🛠️ **Automatic Tool Calling**: AI automatically selects and calls MCP tools based on your questions
21
  - 🔍 Search companies by name or ticker symbol
22
  - 📈 View latest financial data
23
  - 📊 Analyze 3-year and 5-year financial trends
24
  - 💰 Display revenue, net income, EPS, operating expenses, and cash flow metrics
25
+ - 📝 List company SEC filings
26
 
27
+ ## 🚀 Quick Start
28
 
29
+ No configuration needed! Just start asking questions:
 
 
 
30
 
31
+ ### AI Assistant Tab
32
+
33
+ Ask natural language questions:
34
+ - "Show me Apple's latest financial data"
35
+ - "What's NVIDIA's 3-year trend?"
36
+ - "Compare Tesla's revenue with expenses"
37
+ - "How is Microsoft performing?"
38
+ - "Give me Alibaba's financial overview"
39
+
40
+ The AI will automatically:
41
+ 1. 🧠 Understand your question
42
+ 2. 🔧 Call the appropriate MCP tools
43
+ 3. 📊 Analyze the data
44
+ 4. 💬 Provide a comprehensive answer
45
+
46
+ ### Direct Query Tab
47
+
48
+ For structured queries:
49
+ - Enter company name or ticker symbol (e.g., NVIDIA, AAPL, Microsoft)
50
+ - Select query type:
51
+ - **Latest Financial Data**: Most recent fiscal year data
52
+ - **3-Year Trends**: Financial trends over 3 years
53
+ - **5-Year Trends**: Financial trends over 5 years
54
+ - **Company Filings**: List of SEC filings
55
+
56
+ ## 📊 Example Questions
57
+
58
+ **General inquiries:**
59
+ - "What can you tell me about Apple?"
60
+ - "How is Tesla doing financially?"
61
+
62
+ **Specific data:**
63
+ - "Show me NVIDIA's revenue for the last 3 years"
64
+ - "What's Microsoft's latest EPS?"
65
+
66
+ **Comparisons:**
67
+ - "Compare Amazon's revenue and expenses"
68
+ - "How does Google's cash flow look?"
69
+
70
+ **Trends:**
71
+ - "Give me a 5-year financial overview of Alibaba"
72
+ - "Show me Meta's financial trends"
73
+
74
+ ## 💾 Data Source
75
 
76
  SEC EDGAR data via MCP Server: https://huggingface.co/spaces/JC321/EasyReportDateMCP
77
 
78
+ ## 🛠️ Technology Stack
79
 
80
+ - **Frontend**: Gradio 6.0.1
81
  - **Backend**: Python with requests
82
+ - **AI Model**: Qwen/Qwen2.5-72B-Instruct (via Hugging Face Inference API)
83
+ - **MCP Protocol**: FastMCP with HTTP transport (stateless)
84
  - **Data Source**: SEC EDGAR via MCP Server
85
+
86
+ ## 💡 Tips
87
+
88
+ - The AI understands context, so you can ask follow-up questions
89
+ - You can ask about multiple companies in one conversation
90
+ - Both company names and ticker symbols work (e.g., "Apple" or "AAPL")
91
+ - The AI will show which tools it used to answer your question
92
+
93
+ ## 👍 Supported Companies
94
+
95
+ All US-listed companies in SEC EDGAR database, including:
96
+ - Tech: Apple, Microsoft, NVIDIA, Google, Meta, Amazon, Tesla
97
+ - Finance: JPMorgan, Bank of America, Goldman Sachs
98
+ - Retail: Walmart, Target, Costco
99
+ - And many more...
app.py CHANGED
@@ -35,25 +35,13 @@ def create_session_with_retry():
35
  session = create_session_with_retry()
36
 
37
  # 初始化 Hugging Face Inference Client
38
- # 使用环境变量或者免费的公开模型
39
- HF_TOKEN = os.getenv("HF_TOKEN", None) # 可选:如果需要访问私有模型
40
-
41
- # 尝试初始化 client
42
- if HF_TOKEN:
43
- try:
44
- client = InferenceClient(token=HF_TOKEN)
45
- print("✅ Hugging Face client initialized successfully with token")
46
- except Exception as e:
47
- print(f"⚠️ Warning: Failed to initialize Hugging Face client with token: {e}")
48
- client = None
49
- else:
50
- # 没有 token,使用公开访问(有速率限制)
51
- try:
52
- client = InferenceClient()
53
- print("⚠️ Using Hugging Face client without token (rate limited)")
54
- except Exception as e:
55
- print(f"❌ Warning: Failed to initialize Hugging Face client: {e}")
56
- client = None
57
 
58
  # 定义可用的 MCP 工具
59
  MCP_TOOLS = [
@@ -733,17 +721,17 @@ Always be helpful, accurate, and cite the data sources when providing financial
733
  break
734
 
735
  except ValueError as ve:
736
- # API Key 相关错误
737
  error_msg = str(ve)
738
  if "api_key" in error_msg.lower() or "token" in error_msg.lower():
739
- print(f" LLM API authentication error: {ve}")
740
  print("ℹ️ Falling back to simple response logic")
741
  return fallback_chatbot_response(message)
742
  else:
743
  raise
744
  except Exception as e:
745
- # 其他 LLM API 错误
746
- print(f" LLM API error: {e}")
747
  print("ℹ️ Falling back to simple response logic")
748
  return fallback_chatbot_response(message)
749
 
@@ -826,29 +814,14 @@ def query_with_status(company, query_type):
826
  with gr.Blocks(title="SEC Financial Data Query Assistant") as demo:
827
  gr.Markdown("# 🤖 SEC Financial Data Query Assistant")
828
 
829
- # 显示 HF_TOKEN 状态提示
830
- if not HF_TOKEN:
831
- gr.Markdown("""
832
- <div style='padding: 15px; background: #fff3cd; border-left: 4px solid #ffc107; margin: 10px 0; border-radius: 4px;'>
833
- <strong>⚠️ Note:</strong> AI Assistant is running in <strong>rate-limited mode</strong> without HF_TOKEN.
834
- For better performance, set the <code>HF_TOKEN</code> environment variable in your Space settings.
835
- <br><br>
836
- <strong>How to get your token:</strong>
837
- <ol>
838
- <li>Go to <a href="https://huggingface.co/settings/tokens" target="_blank">Hugging Face Tokens</a></li>
839
- <li>Create a new token (Read access is sufficient)</li>
840
- <li>Add it as a Secret in your Space settings: Settings → Repository secrets → New secret</li>
841
- <li>Name: <code>HF_TOKEN</code>, Value: <code>your_token_here</code></li>
842
- <li>Restart the Space</li>
843
- </ol>
844
- </div>
845
- """)
846
- else:
847
- gr.Markdown("""
848
- <div style='padding: 15px; background: #d4edda; border-left: 4px solid #28a745; margin: 10px 0; border-radius: 4px;'>
849
- <strong>✅ AI Mode Active:</strong> Full LLM capabilities enabled with Qwen/Qwen2.5-72B-Instruct model.
850
- </div>
851
- """)
852
 
853
  with gr.Tab("AI Assistant"):
854
  # 使用 Gradio ChatInterface(兼容 4.44.1)
 
35
  session = create_session_with_retry()
36
 
37
  # 初始化 Hugging Face Inference Client
38
+ # 直接使用免费的公开 API,无需 token
39
+ try:
40
+ client = InferenceClient()
41
+ print("✅ Hugging Face client initialized (free tier)")
42
+ except Exception as e:
43
+ print(f"❌ Warning: Failed to initialize Hugging Face client: {e}")
44
+ client = None
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  # 定义可用的 MCP 工具
47
  MCP_TOOLS = [
 
721
  break
722
 
723
  except ValueError as ve:
724
+ # API Key 相关错误(虽然我们不使用 token,但仍然可能出现)
725
  error_msg = str(ve)
726
  if "api_key" in error_msg.lower() or "token" in error_msg.lower():
727
+ print(f"⚠️ LLM API rate limit or authentication issue: {ve}")
728
  print("ℹ️ Falling back to simple response logic")
729
  return fallback_chatbot_response(message)
730
  else:
731
  raise
732
  except Exception as e:
733
+ # 其他 LLM API 错误(如速率限制)
734
+ print(f"⚠️ LLM API error (possibly rate limited): {e}")
735
  print("ℹ️ Falling back to simple response logic")
736
  return fallback_chatbot_response(message)
737
 
 
814
  with gr.Blocks(title="SEC Financial Data Query Assistant") as demo:
815
  gr.Markdown("# 🤖 SEC Financial Data Query Assistant")
816
 
817
+ # 显示 AI 功能说明
818
+ gr.Markdown("""
819
+ <div style='padding: 15px; background: #d4edda; border-left: 4px solid #28a745; margin: 10px 0; border-radius: 4px;'>
820
+ <strong>✅ AI Assistant Enabled:</strong> Powered by Qwen/Qwen2.5-72B-Instruct model with automatic MCP tool calling.
821
+ <br>
822
+ <strong>💬 Ask me anything:</strong> I can understand natural language and automatically fetch financial data when needed!
823
+ </div>
824
+ """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
825
 
826
  with gr.Tab("AI Assistant"):
827
  # 使用 Gradio ChatInterface(兼容 4.44.1)