JC321 commited on
Commit
7357766
·
verified ·
1 Parent(s): 274bec9

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -3
app.py CHANGED
@@ -73,7 +73,8 @@ def query_financial_data(company_name, query_type):
73
  query_type_mapping = {
74
  "Latest Financial Data": "最新财务数据",
75
  "3-Year Trends": "3年趋势",
76
- "5-Year Trends": "5年趋势"
 
77
  }
78
  internal_query_type = query_type_mapping.get(query_type, query_type)
79
 
@@ -225,6 +226,51 @@ def query_financial_data(company_name, query_type):
225
 
226
  result += f"| {period_prefix}{period} | {format_value(rev)} | {format_value(inc)} | {format_value(eps_val, False)} | {format_value(opex)} | {format_value(ocf)} | {source_link} |\n"
227
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
  return result
229
 
230
  except requests.exceptions.RequestException as e:
@@ -317,7 +363,7 @@ with gr.Blocks(title="SEC Financial Data Query Assistant", css="""
317
  scale=2
318
  )
319
  query_type = gr.Radio(
320
- ["Latest Financial Data", "3-Year Trends", "5-Year Trends"],
321
  label="Query Type",
322
  value="Latest Financial Data",
323
  scale=1
@@ -332,7 +378,7 @@ with gr.Blocks(title="SEC Financial Data Query Assistant", css="""
332
  ["NVIDIA", "Latest Financial Data"],
333
  ["Apple", "3-Year Trends"],
334
  ["Microsoft", "5-Year Trends"],
335
- ["Alibaba", "Latest Financial Data"],
336
  ["Tesla", "3-Year Trends"]
337
  ],
338
  inputs=[company_input, query_type],
 
73
  query_type_mapping = {
74
  "Latest Financial Data": "最新财务数据",
75
  "3-Year Trends": "3年趋势",
76
+ "5-Year Trends": "5年趋势",
77
+ "Company Filings": "公司报表列表"
78
  }
79
  internal_query_type = query_type_mapping.get(query_type, query_type)
80
 
 
226
 
227
  result += f"| {period_prefix}{period} | {format_value(rev)} | {format_value(inc)} | {format_value(eps_val, False)} | {format_value(opex)} | {format_value(ocf)} | {source_link} |\n"
228
 
229
+ elif internal_query_type == "公司报表列表":
230
+ # 查询公司所有报表
231
+ filings_resp = requests.post(
232
+ f"{MCP_URL}/api/get_company_filings",
233
+ json={"cik": cik, "limit": 50}, # 限制最多50条
234
+ headers=HEADERS,
235
+ timeout=60
236
+ )
237
+
238
+ if filings_resp.status_code != 200:
239
+ return result + f"❌ Server Error: HTTP {filings_resp.status_code}\n\n{filings_resp.text[:500]}"
240
+
241
+ try:
242
+ filings_data = filings_resp.json()
243
+ except (ValueError, KeyError) as e:
244
+ return result + f"❌ JSON Parse Error: {str(e)}\n\n{filings_resp.text[:500]}"
245
+
246
+ if isinstance(filings_data, dict) and filings_data.get("error"):
247
+ return result + f"❌ {filings_data['error']}"
248
+
249
+ filings = filings_data.get('filings', []) if isinstance(filings_data, dict) else filings_data
250
+
251
+ result += f"## Company Filings ({len(filings)} records)\n\n"
252
+ result += "| Form Type | Filing Date | Accession Number | Primary Document |\n"
253
+ result += "|-----------|-------------|------------------|------------------|\n"
254
+
255
+ for filing in filings:
256
+ form_type = filing.get('form_type', 'N/A')
257
+ filing_date = filing.get('filing_date', 'N/A')
258
+ accession_num = filing.get('accession_number', 'N/A')
259
+ primary_doc = filing.get('primary_document', 'N/A')
260
+
261
+ # 创建 SEC EDGAR 原始文档链接
262
+ if accession_num != 'N/A' and primary_doc != 'N/A':
263
+ # 移除 accession_number 中的连字符以匹配 SEC URL 格式
264
+ acc_no_clean = accession_num.replace('-', '')
265
+ doc_url = f"https://www.sec.gov/Archives/edgar/data/{cik}/{acc_no_clean}/{primary_doc}"
266
+ form_link = f"[{form_type}]({doc_url})"
267
+ primary_doc_link = f"[{primary_doc}]({doc_url})"
268
+ else:
269
+ form_link = form_type
270
+ primary_doc_link = primary_doc
271
+
272
+ result += f"| {form_link} | {filing_date} | {accession_num} | {primary_doc_link} |\n"
273
+
274
  return result
275
 
276
  except requests.exceptions.RequestException as e:
 
363
  scale=2
364
  )
365
  query_type = gr.Radio(
366
+ ["Latest Financial Data", "3-Year Trends", "5-Year Trends", "Company Filings"],
367
  label="Query Type",
368
  value="Latest Financial Data",
369
  scale=1
 
378
  ["NVIDIA", "Latest Financial Data"],
379
  ["Apple", "3-Year Trends"],
380
  ["Microsoft", "5-Year Trends"],
381
+ ["Alibaba", "Company Filings"],
382
  ["Tesla", "3-Year Trends"]
383
  ],
384
  inputs=[company_input, query_type],