Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -78,48 +78,85 @@ def advanced_search_company(company_input: str) -> dict:
|
|
| 78 |
result = financial_analyzer.search_company(company_input)
|
| 79 |
return result if not result.get("error") else {"error": result["error"]}
|
| 80 |
|
| 81 |
-
# Gradio wrapper functions
|
| 82 |
def gradio_search_company(company_name: str):
|
| 83 |
"""Gradio wrapper for search_company"""
|
| 84 |
if not company_name or not company_name.strip():
|
| 85 |
return json.dumps({"error": "Company name cannot be empty"}, indent=2)
|
| 86 |
try:
|
|
|
|
|
|
|
| 87 |
result = search_company(company_name.strip())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
return json.dumps(result, indent=2)
|
|
|
|
|
|
|
| 89 |
except Exception as e:
|
| 90 |
-
|
|
|
|
|
|
|
| 91 |
|
| 92 |
def gradio_get_company_info(cik: str):
|
| 93 |
"""Gradio wrapper for get_company_info"""
|
| 94 |
if not cik or not cik.strip():
|
| 95 |
return json.dumps({"error": "CIK cannot be empty"}, indent=2)
|
| 96 |
try:
|
|
|
|
|
|
|
| 97 |
result = get_company_info(cik.strip())
|
|
|
|
|
|
|
|
|
|
| 98 |
return json.dumps(result, indent=2)
|
|
|
|
|
|
|
| 99 |
except Exception as e:
|
| 100 |
-
|
|
|
|
|
|
|
| 101 |
|
| 102 |
def gradio_extract_metrics(cik: str, years: float):
|
| 103 |
"""Gradio wrapper for extract_financial_metrics"""
|
| 104 |
if not cik or not cik.strip():
|
| 105 |
return json.dumps({"error": "CIK cannot be empty"}, indent=2)
|
| 106 |
try:
|
| 107 |
-
|
| 108 |
years_int = int(years)
|
|
|
|
| 109 |
result = extract_financial_metrics(cik.strip(), years_int)
|
|
|
|
|
|
|
|
|
|
| 110 |
return json.dumps(result, indent=2)
|
|
|
|
|
|
|
| 111 |
except Exception as e:
|
| 112 |
-
|
|
|
|
|
|
|
| 113 |
|
| 114 |
def gradio_get_latest(cik: str):
|
| 115 |
"""Gradio wrapper for get_latest_financial_data"""
|
| 116 |
if not cik or not cik.strip():
|
| 117 |
return json.dumps({"error": "CIK cannot be empty"}, indent=2)
|
| 118 |
try:
|
|
|
|
|
|
|
| 119 |
result = get_latest_financial_data(cik.strip())
|
|
|
|
|
|
|
|
|
|
| 120 |
return json.dumps(result, indent=2)
|
|
|
|
|
|
|
| 121 |
except Exception as e:
|
| 122 |
-
|
|
|
|
|
|
|
| 123 |
|
| 124 |
# Create Gradio interface
|
| 125 |
with gr.Blocks(title="SEC Financial Data MCP Server", theme=gr.themes.Soft()) as demo:
|
|
|
|
| 78 |
result = financial_analyzer.search_company(company_input)
|
| 79 |
return result if not result.get("error") else {"error": result["error"]}
|
| 80 |
|
| 81 |
+
# Gradio wrapper functions (添加调试和超时处理)
|
| 82 |
def gradio_search_company(company_name: str):
|
| 83 |
"""Gradio wrapper for search_company"""
|
| 84 |
if not company_name or not company_name.strip():
|
| 85 |
return json.dumps({"error": "Company name cannot be empty"}, indent=2)
|
| 86 |
try:
|
| 87 |
+
import sys
|
| 88 |
+
print(f"[DEBUG] Searching company: {company_name.strip()}", file=sys.stderr)
|
| 89 |
result = search_company(company_name.strip())
|
| 90 |
+
print(f"[DEBUG] Search result type: {type(result)}", file=sys.stderr)
|
| 91 |
+
print(f"[DEBUG] Search result: {result}", file=sys.stderr)
|
| 92 |
+
# Ensure result is a dict
|
| 93 |
+
if not isinstance(result, dict):
|
| 94 |
+
result = {"error": f"Unexpected result type: {type(result)}"}
|
| 95 |
return json.dumps(result, indent=2)
|
| 96 |
+
except TimeoutError as e:
|
| 97 |
+
return json.dumps({"error": f"Request timeout: {str(e)}"}, indent=2)
|
| 98 |
except Exception as e:
|
| 99 |
+
import traceback
|
| 100 |
+
traceback.print_exc()
|
| 101 |
+
return json.dumps({"error": f"Exception: {str(e)}", "type": str(type(e))}, indent=2)
|
| 102 |
|
| 103 |
def gradio_get_company_info(cik: str):
|
| 104 |
"""Gradio wrapper for get_company_info"""
|
| 105 |
if not cik or not cik.strip():
|
| 106 |
return json.dumps({"error": "CIK cannot be empty"}, indent=2)
|
| 107 |
try:
|
| 108 |
+
import sys
|
| 109 |
+
print(f"[DEBUG] Getting company info for CIK: {cik.strip()}", file=sys.stderr)
|
| 110 |
result = get_company_info(cik.strip())
|
| 111 |
+
print(f"[DEBUG] Company info result: {result}", file=sys.stderr)
|
| 112 |
+
if not isinstance(result, dict):
|
| 113 |
+
result = {"error": f"Unexpected result type: {type(result)}"}
|
| 114 |
return json.dumps(result, indent=2)
|
| 115 |
+
except TimeoutError as e:
|
| 116 |
+
return json.dumps({"error": f"Request timeout: {str(e)}"}, indent=2)
|
| 117 |
except Exception as e:
|
| 118 |
+
import traceback
|
| 119 |
+
traceback.print_exc()
|
| 120 |
+
return json.dumps({"error": f"Exception: {str(e)}", "type": str(type(e))}, indent=2)
|
| 121 |
|
| 122 |
def gradio_extract_metrics(cik: str, years: float):
|
| 123 |
"""Gradio wrapper for extract_financial_metrics"""
|
| 124 |
if not cik or not cik.strip():
|
| 125 |
return json.dumps({"error": "CIK cannot be empty"}, indent=2)
|
| 126 |
try:
|
| 127 |
+
import sys
|
| 128 |
years_int = int(years)
|
| 129 |
+
print(f"[DEBUG] Extracting metrics for CIK: {cik.strip()}, Years: {years_int}", file=sys.stderr)
|
| 130 |
result = extract_financial_metrics(cik.strip(), years_int)
|
| 131 |
+
print(f"[DEBUG] Extract metrics result: {result}", file=sys.stderr)
|
| 132 |
+
if not isinstance(result, dict):
|
| 133 |
+
result = {"error": f"Unexpected result type: {type(result)}"}
|
| 134 |
return json.dumps(result, indent=2)
|
| 135 |
+
except TimeoutError as e:
|
| 136 |
+
return json.dumps({"error": f"Request timeout: {str(e)}"}, indent=2)
|
| 137 |
except Exception as e:
|
| 138 |
+
import traceback
|
| 139 |
+
traceback.print_exc()
|
| 140 |
+
return json.dumps({"error": f"Exception: {str(e)}", "type": str(type(e))}, indent=2)
|
| 141 |
|
| 142 |
def gradio_get_latest(cik: str):
|
| 143 |
"""Gradio wrapper for get_latest_financial_data"""
|
| 144 |
if not cik or not cik.strip():
|
| 145 |
return json.dumps({"error": "CIK cannot be empty"}, indent=2)
|
| 146 |
try:
|
| 147 |
+
import sys
|
| 148 |
+
print(f"[DEBUG] Getting latest data for CIK: {cik.strip()}", file=sys.stderr)
|
| 149 |
result = get_latest_financial_data(cik.strip())
|
| 150 |
+
print(f"[DEBUG] Latest data result: {result}", file=sys.stderr)
|
| 151 |
+
if not isinstance(result, dict):
|
| 152 |
+
result = {"error": f"Unexpected result type: {type(result)}"}
|
| 153 |
return json.dumps(result, indent=2)
|
| 154 |
+
except TimeoutError as e:
|
| 155 |
+
return json.dumps({"error": f"Request timeout: {str(e)}"}, indent=2)
|
| 156 |
except Exception as e:
|
| 157 |
+
import traceback
|
| 158 |
+
traceback.print_exc()
|
| 159 |
+
return json.dumps({"error": f"Exception: {str(e)}", "type": str(type(e))}, indent=2)
|
| 160 |
|
| 161 |
# Create Gradio interface
|
| 162 |
with gr.Blocks(title="SEC Financial Data MCP Server", theme=gr.themes.Soft()) as demo:
|