Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -49,6 +49,17 @@ logger = logging.getLogger(__name__)
|
|
| 49 |
OUTPUTS_DIR = Path("outputs")
|
| 50 |
OUTPUTS_DIR.mkdir(exist_ok=True)
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
# ---------------------------------------------------------------------------
|
| 53 |
# Custom CSS β Light, readable theme that works on HuggingFace Spaces
|
| 54 |
# ---------------------------------------------------------------------------
|
|
@@ -1648,32 +1659,24 @@ with gr.Blocks(
|
|
| 1648 |
"- **Mistral** (Panel A) β pragmatic applied IS perspective\n"
|
| 1649 |
"- **Gemini** (Panel B) β broad technology futures perspective\n"
|
| 1650 |
"- **Claude** (Synthesis Judge) β consensus arbitration and final recommendation\n\n"
|
| 1651 |
-
"API keys are
|
|
|
|
|
|
|
| 1652 |
)
|
| 1653 |
|
| 1654 |
-
|
| 1655 |
-
|
| 1656 |
-
|
| 1657 |
-
|
| 1658 |
-
|
| 1659 |
-
|
| 1660 |
-
|
| 1661 |
-
|
| 1662 |
-
|
| 1663 |
-
|
| 1664 |
-
placeholder="AIza...",
|
| 1665 |
-
type="password",
|
| 1666 |
-
show_label=True,
|
| 1667 |
-
)
|
| 1668 |
-
anthropic_key_input = gr.Textbox(
|
| 1669 |
-
label="Anthropic API Key (synthesis judge)",
|
| 1670 |
-
placeholder="sk-ant-...",
|
| 1671 |
-
type="password",
|
| 1672 |
-
show_label=True,
|
| 1673 |
-
)
|
| 1674 |
|
| 1675 |
btn_run_council = gr.Button("π Convene Research Council", variant="primary")
|
| 1676 |
-
council_status = gr.Markdown("*
|
| 1677 |
|
| 1678 |
with gr.Row():
|
| 1679 |
with gr.Column():
|
|
@@ -1715,7 +1718,6 @@ with gr.Blocks(
|
|
| 1715 |
|
| 1716 |
def handle_run_council(
|
| 1717 |
taxonomy_map, topic_df,
|
| 1718 |
-
mistral_key, gemini_key, anthropic_key,
|
| 1719 |
progress=gr.Progress(track_tqdm=True)
|
| 1720 |
):
|
| 1721 |
if not taxonomy_map:
|
|
@@ -1723,9 +1725,11 @@ with gr.Blocks(
|
|
| 1723 |
"<div class='error-box'>β Run taxonomy mapping first (Tab 3 or full pipeline).</div>",
|
| 1724 |
"", "", "", "", gr.update()
|
| 1725 |
)
|
| 1726 |
-
if not any([
|
| 1727 |
return (
|
| 1728 |
-
"<div class='error-box'>β
|
|
|
|
|
|
|
| 1729 |
"", "", "", "", gr.update()
|
| 1730 |
)
|
| 1731 |
|
|
@@ -1735,9 +1739,9 @@ with gr.Blocks(
|
|
| 1735 |
result = run_agentic_council(
|
| 1736 |
taxonomy_map=taxonomy_map,
|
| 1737 |
topic_df=topic_df,
|
| 1738 |
-
mistral_api_key=
|
| 1739 |
-
gemini_api_key=
|
| 1740 |
-
anthropic_api_key=
|
| 1741 |
)
|
| 1742 |
progress(0.9, desc="Saving reportβ¦")
|
| 1743 |
saved = _safe_save_json(result, "council_report.json")
|
|
@@ -1762,7 +1766,6 @@ with gr.Blocks(
|
|
| 1762 |
fn=handle_run_council,
|
| 1763 |
inputs=[
|
| 1764 |
state_taxonomy_map, state_topic_df,
|
| 1765 |
-
mistral_key_input, gemini_key_input, anthropic_key_input,
|
| 1766 |
],
|
| 1767 |
outputs=[
|
| 1768 |
council_status,
|
|
|
|
| 49 |
OUTPUTS_DIR = Path("outputs")
|
| 50 |
OUTPUTS_DIR.mkdir(exist_ok=True)
|
| 51 |
|
| 52 |
+
# ---------------------------------------------------------------------------
|
| 53 |
+
# API Keys β loaded from HuggingFace Secrets (Environment Variables)
|
| 54 |
+
# Set these in your Space: Settings β Variables and Secrets
|
| 55 |
+
# MISTRAL_API_KEY β your Mistral key (sk-...)
|
| 56 |
+
# GEMINI_API_KEY β your Google key (AIza...)
|
| 57 |
+
# ANTHROPIC_API_KEY β your Anthropic key (sk-ant-...)
|
| 58 |
+
# ---------------------------------------------------------------------------
|
| 59 |
+
MISTRAL_API_KEY = os.environ.get("MISTRAL_API_KEY", "")
|
| 60 |
+
GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY", "")
|
| 61 |
+
ANTHROPIC_API_KEY = os.environ.get("ANTHROPIC_API_KEY", "")
|
| 62 |
+
|
| 63 |
# ---------------------------------------------------------------------------
|
| 64 |
# Custom CSS β Light, readable theme that works on HuggingFace Spaces
|
| 65 |
# ---------------------------------------------------------------------------
|
|
|
|
| 1659 |
"- **Mistral** (Panel A) β pragmatic applied IS perspective\n"
|
| 1660 |
"- **Gemini** (Panel B) β broad technology futures perspective\n"
|
| 1661 |
"- **Claude** (Synthesis Judge) β consensus arbitration and final recommendation\n\n"
|
| 1662 |
+
"API keys are loaded automatically from HuggingFace Secrets "
|
| 1663 |
+
"(`MISTRAL_API_KEY`, `GEMINI_API_KEY`, `ANTHROPIC_API_KEY`). "
|
| 1664 |
+
"Configure them in your Space under **Settings β Variables and Secrets**."
|
| 1665 |
)
|
| 1666 |
|
| 1667 |
+
# Key-status indicator β shows which secrets are present at load time
|
| 1668 |
+
_key_lines = ["**π Secret Status (loaded at startup):**"]
|
| 1669 |
+
for _label, _val in [
|
| 1670 |
+
("MISTRAL_API_KEY", MISTRAL_API_KEY),
|
| 1671 |
+
("GEMINI_API_KEY", GEMINI_API_KEY),
|
| 1672 |
+
("ANTHROPIC_API_KEY", ANTHROPIC_API_KEY),
|
| 1673 |
+
]:
|
| 1674 |
+
_icon = "β
present" if _val else "β missing"
|
| 1675 |
+
_key_lines.append(f"- `{_label}`: {_icon}")
|
| 1676 |
+
gr.Markdown("\n".join(_key_lines))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1677 |
|
| 1678 |
btn_run_council = gr.Button("π Convene Research Council", variant="primary")
|
| 1679 |
+
council_status = gr.Markdown("*Run taxonomy mapping first (Tab 3 or full pipeline).*")
|
| 1680 |
|
| 1681 |
with gr.Row():
|
| 1682 |
with gr.Column():
|
|
|
|
| 1718 |
|
| 1719 |
def handle_run_council(
|
| 1720 |
taxonomy_map, topic_df,
|
|
|
|
| 1721 |
progress=gr.Progress(track_tqdm=True)
|
| 1722 |
):
|
| 1723 |
if not taxonomy_map:
|
|
|
|
| 1725 |
"<div class='error-box'>β Run taxonomy mapping first (Tab 3 or full pipeline).</div>",
|
| 1726 |
"", "", "", "", gr.update()
|
| 1727 |
)
|
| 1728 |
+
if not any([MISTRAL_API_KEY, GEMINI_API_KEY, ANTHROPIC_API_KEY]):
|
| 1729 |
return (
|
| 1730 |
+
"<div class='error-box'>β No API keys found. "
|
| 1731 |
+
"Add MISTRAL_API_KEY, GEMINI_API_KEY, or ANTHROPIC_API_KEY "
|
| 1732 |
+
"in your Space Settings β Variables and Secrets.</div>",
|
| 1733 |
"", "", "", "", gr.update()
|
| 1734 |
)
|
| 1735 |
|
|
|
|
| 1739 |
result = run_agentic_council(
|
| 1740 |
taxonomy_map=taxonomy_map,
|
| 1741 |
topic_df=topic_df,
|
| 1742 |
+
mistral_api_key=MISTRAL_API_KEY,
|
| 1743 |
+
gemini_api_key=GEMINI_API_KEY,
|
| 1744 |
+
anthropic_api_key=ANTHROPIC_API_KEY,
|
| 1745 |
)
|
| 1746 |
progress(0.9, desc="Saving reportβ¦")
|
| 1747 |
saved = _safe_save_json(result, "council_report.json")
|
|
|
|
| 1766 |
fn=handle_run_council,
|
| 1767 |
inputs=[
|
| 1768 |
state_taxonomy_map, state_topic_df,
|
|
|
|
| 1769 |
],
|
| 1770 |
outputs=[
|
| 1771 |
council_status,
|