Spaces:
Runtime error
Runtime error
Download eugene/app.py from Rex165/eugene-intelligence: direct link, hf CLI and curl.
- Browser
- Download file 7.09 kB
-
https://huggingface.co/spaces/Rex165/eugene-intelligence/resolve/main/eugene/app.py
- Command line
-
hf download hf://spaces/Rex165/eugene-intelligence/eugene/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Rex165/eugene-intelligence/resolve/main/eugene/app.py
7.09 kB
| """ | |
| Eugene Intelligence v0.4 β HuggingFace Space | |
| Financial context for AI. Every number traced to source. | |
| """ | |
| import json | |
| import gradio as gr | |
| from eugene.router import query, capabilities, VALID_EXTRACTS | |
| from eugene.sources.fred import get_category, get_series, get_all, FRED_SERIES | |
| from eugene.concepts import VALID_CONCEPTS | |
| VERSION = "0.4.0" | |
| def sec_query(identifier, extract, period, concept, form, section, limit): | |
| """Run SEC query and return formatted JSON.""" | |
| if not identifier.strip(): | |
| return json.dumps({"error": "Please enter a ticker, CIK, or accession number."}, indent=2) | |
| params = { | |
| "period": period, | |
| "concept": concept if concept else None, | |
| "form": form if form else None, | |
| "section": section if section else None, | |
| "limit": int(limit), | |
| } | |
| result = query( | |
| identifier.strip().upper(), | |
| extract, | |
| **{k: v for k, v in params.items() if v is not None} | |
| ) | |
| return json.dumps(result, indent=2, default=str) | |
| def economics_query(category, series_id): | |
| """Run FRED economics query.""" | |
| if series_id and series_id.strip(): | |
| result = get_series(series_id.strip().upper()) | |
| elif category == "all": | |
| result = get_all() | |
| else: | |
| result = get_category(category) | |
| return json.dumps(result, indent=2, default=str) | |
| def get_caps(): | |
| """Return capabilities.""" | |
| return json.dumps(capabilities(), indent=2) | |
| # ββ Build UI ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| with gr.Blocks( | |
| title="Eugene Intelligence v0.4", | |
| theme=gr.themes.Base(), | |
| css=""" | |
| .header { text-align: center; margin-bottom: 1rem; } | |
| .header h1 { margin-bottom: 0.25rem; } | |
| .header p { color: #666; margin-top: 0; } | |
| """ | |
| ) as demo: | |
| gr.HTML(""" | |
| <div class="header"> | |
| <h1>ποΈ Eugene Intelligence v0.4</h1> | |
| <p>Financial context for AI. Every number traced to source.</p> | |
| </div> | |
| """) | |
| with gr.Tabs(): | |
| # ββ SEC Tab βββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| with gr.Tab("SEC EDGAR"): | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| identifier = gr.Textbox( | |
| label="Identifier", | |
| placeholder="AAPL, 320193, or accession number", | |
| value="AAPL", | |
| ) | |
| extract = gr.Dropdown( | |
| label="Extract", | |
| choices=VALID_EXTRACTS, | |
| value="financials", | |
| ) | |
| period = gr.Radio( | |
| label="Period (financials)", | |
| choices=["FY", "Q"], | |
| value="FY", | |
| ) | |
| limit = gr.Slider( | |
| label="Limit", | |
| minimum=1, maximum=20, step=1, value=5, | |
| ) | |
| concept = gr.Textbox( | |
| label="Concept (optional)", | |
| placeholder="revenue, net_income, eps_diluted...", | |
| ) | |
| form = gr.Textbox( | |
| label="Form filter (optional)", | |
| placeholder="10-K, 10-Q, 8-K, 4...", | |
| ) | |
| section = gr.Textbox( | |
| label="Section (optional)", | |
| placeholder="mdna, risk_factors, business...", | |
| ) | |
| sec_btn = gr.Button("Query SEC", variant="primary") | |
| with gr.Column(scale=2): | |
| sec_output = gr.Code( | |
| label="Response", | |
| language="json", | |
| lines=30, | |
| ) | |
| sec_btn.click( | |
| fn=sec_query, | |
| inputs=[identifier, extract, period, concept, form, section, limit], | |
| outputs=sec_output, | |
| ) | |
| gr.Examples( | |
| examples=[ | |
| ["AAPL", "financials", "FY", "", "", "", 5], | |
| ["NVDA", "financials", "FY", "revenue", "", "", 5], | |
| ["TSLA", "profile", "FY", "", "", "", 5], | |
| ["JPM", "filings", "FY", "", "10-K", "", 5], | |
| ["MSFT", "financials", "Q", "", "", "", 8], | |
| ["BA", "sections", "FY", "", "", "mdna", 1], | |
| ], | |
| inputs=[identifier, extract, period, concept, form, section, limit], | |
| ) | |
| # ββ Economics Tab βββββββββββββββββββββββββββββββββββββββββββββββββ | |
| with gr.Tab("Economics (FRED)"): | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| econ_category = gr.Dropdown( | |
| label="Category", | |
| choices=["all", "inflation", "employment", "gdp", "housing", | |
| "consumer", "manufacturing", "rates", "money", "treasury"], | |
| value="treasury", | |
| ) | |
| econ_series = gr.Textbox( | |
| label="Specific series ID (optional, overrides category)", | |
| placeholder="CPIAUCSL, UNRATE, DGS10...", | |
| ) | |
| econ_btn = gr.Button("Query FRED", variant="primary") | |
| with gr.Column(scale=2): | |
| econ_output = gr.Code( | |
| label="Response", | |
| language="json", | |
| lines=30, | |
| ) | |
| econ_btn.click( | |
| fn=economics_query, | |
| inputs=[econ_category, econ_series], | |
| outputs=econ_output, | |
| ) | |
| # ββ Capabilities Tab ββββββββββββββββββββββββββββββββββββββββββββββ | |
| with gr.Tab("Capabilities"): | |
| caps_btn = gr.Button("Show Capabilities") | |
| caps_output = gr.Code(language="json", lines=30) | |
| caps_btn.click(fn=get_caps, outputs=caps_output) | |
| gr.Markdown(f""" | |
| ### Canonical Concepts | |
| `{', '.join(VALID_CONCEPTS)}` | |
| ### Extracts | |
| `{', '.join(VALID_EXTRACTS)}` | |
| ### Links | |
| - **GitHub**: [Matthew-Anyiam/eugene-data-labs](https://github.com/Matthew-Anyiam/eugene-data-labs) | |
| - **API**: [eugene-data-labs-production.up.railway.app](https://eugene-data-labs-production.up.railway.app) | |
| - **MCP**: [mcpservers.org](https://mcpservers.org/server/matthew-anyiam/eugene-data-labs) | |
| - **PyPI**: `pip install eugene-data-labs` | |
| """) | |
| if __name__ == "__main__": | |
| demo.launch(server_name="0.0.0.0", server_port=7860) | |