Spaces:
Running on Zero
Running on Zero
Download examples/app.py from Brianferrell787/range: direct link, hf CLI and curl.
- Browser
- Download file 2.96 kB
-
https://huggingface.co/spaces/Brianferrell787/range/resolve/main/examples/app.py
- Command line
-
hf download hf://spaces/Brianferrell787/range/examples/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Brianferrell787/range/resolve/main/examples/app.py
2.96 kB
| """Local Gradio demo for one timestamped economy or financial-news article.""" | |
| from __future__ import annotations | |
| from functools import lru_cache | |
| import gradio as gr | |
| from range_curate.examples.general_economy import RelevanceEngine | |
| def _engine() -> RelevanceEngine: | |
| return RelevanceEngine() | |
| def predict_article(text: str, timestamp: str): | |
| """Return a compact decision, explanation, and Mermaid diagram source.""" | |
| if not text or not text.strip(): | |
| raise gr.Error("Enter article text before running a prediction.") | |
| if not timestamp or not timestamp.strip(): | |
| raise gr.Error("Enter an ISO 8601 publication timestamp.") | |
| try: | |
| prediction = _engine().predict( | |
| text, | |
| timestamp=timestamp, | |
| article_id="interactive-demo", | |
| source="gradio-local", | |
| ) | |
| except (TypeError, ValueError) as exc: | |
| raise gr.Error(f"The article or timestamp is invalid: {exc}") from exc | |
| explanation = _engine().explain(prediction, format="text", detail="summary") | |
| diagram = _engine().explain(prediction, format="mermaid", detail="summary") | |
| return prediction.summary(), explanation, diagram | |
| def build_demo() -> gr.Blocks: | |
| with gr.Blocks(title="RANGE") as demo: | |
| gr.Markdown( | |
| "# RANGE\n" | |
| "**Rapid Annotation, Normalization, and Gating Engine — General Economy example**\n\n" | |
| "Screen timestamped economic and financial news against the bundled " | |
| "general-economy taxonomy. Everything runs in this Python process." | |
| ) | |
| with gr.Row(): | |
| with gr.Column(scale=3): | |
| article = gr.Textbox( | |
| label="Article text", | |
| lines=12, | |
| value=( | |
| "CPI inflation cooled after the Federal Reserve cut the " | |
| "federal funds rate. The S&P 500 advanced." | |
| ), | |
| ) | |
| timestamp = gr.Textbox( | |
| label="Publication timestamp", | |
| value="2025-01-15T10:30:00-05:00", | |
| info="Use ISO 8601 with a UTC offset when possible.", | |
| ) | |
| run = gr.Button("Predict relevance", variant="primary") | |
| with gr.Column(scale=2): | |
| decision = gr.JSON(label="Decision") | |
| explanation = gr.Markdown(label="Evidence explanation") | |
| diagram = gr.Code( | |
| language="markdown", | |
| label="Mermaid evidence diagram", | |
| lines=16, | |
| ) | |
| run.click( | |
| fn=predict_article, | |
| inputs=[article, timestamp], | |
| outputs=[decision, explanation, diagram], | |
| api_name="predict", | |
| ) | |
| return demo | |
| demo = build_demo() | |
| if __name__ == "__main__": | |
| demo.launch() | |