Spaces:
Runtime error
Runtime error
Upload 18 files
Browse files- app.py +23 -10
- research_agent.py +4 -1
app.py
CHANGED
|
@@ -66,16 +66,25 @@ def ui_explain_detail(ticker):
|
|
| 66 |
if not raw:
|
| 67 |
yield "Run the analysis and select a ticker first."
|
| 68 |
return
|
| 69 |
-
#
|
| 70 |
-
#
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
yield "🤖 _Translator sub-agent (Qwen3-1.7B · llama.cpp) is summarizing…_"
|
| 77 |
final = ""
|
| 78 |
-
for acc in llm_local.chat_stream(prompt, max_tokens=
|
| 79 |
worker="translator"):
|
| 80 |
final = acc
|
| 81 |
yield "🤖 **AI narrative (Translator sub-agent · Qwen3-1.7B):**\n\n" + acc
|
|
@@ -304,8 +313,12 @@ with gr.Blocks(title="Chan Compass · US", **_style_kw) as demo:
|
|
| 304 |
elem_id="detail-log")
|
| 305 |
traces_md = gr.Markdown(research_agent.list_traces())
|
| 306 |
auto_log_timer = gr.Timer(2.0)
|
| 307 |
-
|
| 308 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
|
| 310 |
with gr.Tab("🧠 Model"):
|
| 311 |
gr.Markdown("All AI runs **locally** through **llama.cpp** (llama-cpp-python) with "
|
|
|
|
| 66 |
if not raw:
|
| 67 |
yield "Run the analysis and select a ticker first."
|
| 68 |
return
|
| 69 |
+
# The full Chan ruling chain (Chinese) is kept BACKSTAGE in STATE and fed to
|
| 70 |
+
# the model alongside the English raw read, so the summary reflects the real
|
| 71 |
+
# multi-timeframe reasoning — but the chain is never shown and output is
|
| 72 |
+
# English only. (This restores the merged raw-read + ruling-chain logic.)
|
| 73 |
+
chain = automation.STATE.get("signals_details", {}).get(ticker or "", "")
|
| 74 |
+
chain_core = chain.split("日线买卖点逐项诊断")[0].strip()[:2000] if chain else ""
|
| 75 |
+
prompt = ("You are an equity analyst. Write a SHORT plain-English summary "
|
| 76 |
+
"(≤100 words) for a long-term holder of a US stock: the situation "
|
| 77 |
+
"today, whether to act or wait, and the key price levels.\n"
|
| 78 |
+
"Use the FACT LINE for the numbers, and the RULING CHAIN (a "
|
| 79 |
+
"Chinese multi-timeframe Chan-theory decision log) for the reasoning "
|
| 80 |
+
"— translate and synthesize it; output ENGLISH ONLY, no Chinese "
|
| 81 |
+
"characters, do not quote the log, no disclaimers.\n\n"
|
| 82 |
+
f"FACT LINE:\n{raw}")
|
| 83 |
+
if chain_core:
|
| 84 |
+
prompt += f"\n\nRULING CHAIN (translate & synthesize, don't quote):\n{chain_core}"
|
| 85 |
yield "🤖 _Translator sub-agent (Qwen3-1.7B · llama.cpp) is summarizing…_"
|
| 86 |
final = ""
|
| 87 |
+
for acc in llm_local.chat_stream(prompt, max_tokens=260, temperature=0.2,
|
| 88 |
worker="translator"):
|
| 89 |
final = acc
|
| 90 |
yield "🤖 **AI narrative (Translator sub-agent · Qwen3-1.7B):**\n\n" + acc
|
|
|
|
| 313 |
elem_id="detail-log")
|
| 314 |
traces_md = gr.Markdown(research_agent.list_traces())
|
| 315 |
auto_log_timer = gr.Timer(2.0)
|
| 316 |
+
|
| 317 |
+
def _auto_tick():
|
| 318 |
+
log = "\n".join(automation.STATE["log"][-40:]) or "(no log yet)"
|
| 319 |
+
return log, research_agent.list_traces()
|
| 320 |
+
|
| 321 |
+
auto_log_timer.tick(_auto_tick, None, [auto_log, traces_md])
|
| 322 |
|
| 323 |
with gr.Tab("🧠 Model"):
|
| 324 |
gr.Markdown("All AI runs **locally** through **llama.cpp** (llama-cpp-python) with "
|
research_agent.py
CHANGED
|
@@ -330,7 +330,10 @@ def read_report(fname: str) -> str:
|
|
| 330 |
|
| 331 |
def list_traces() -> str:
|
| 332 |
try:
|
| 333 |
-
fs =
|
|
|
|
|
|
|
|
|
|
| 334 |
if not fs:
|
| 335 |
return "_No traces yet — run a research note first._"
|
| 336 |
return ("**Saved agent traces** (`" + paths.TRACES_DIR + "`):\n" +
|
|
|
|
| 330 |
|
| 331 |
def list_traces() -> str:
|
| 332 |
try:
|
| 333 |
+
fs = [f for f in os.listdir(paths.TRACES_DIR) if f.endswith(".json")]
|
| 334 |
+
fs.sort(key=lambda f: os.path.getmtime(os.path.join(paths.TRACES_DIR, f)),
|
| 335 |
+
reverse=True)
|
| 336 |
+
fs = fs[:20]
|
| 337 |
if not fs:
|
| 338 |
return "_No traces yet — run a research note first._"
|
| 339 |
return ("**Saved agent traces** (`" + paths.TRACES_DIR + "`):\n" +
|