Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -64,17 +64,23 @@ def _mistral(prompt, key):
|
|
| 64 |
|
| 65 |
def _gemini(prompt, key):
|
| 66 |
if not key: return {}
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
# ---------------------------------------------------------------------------
|
| 80 |
# Topic labelling prompt
|
|
@@ -213,13 +219,18 @@ def llm_council(state: PipelineState) -> dict:
|
|
| 213 |
"single": round((total - n_triple - n_two) / total * 100),
|
| 214 |
}
|
| 215 |
|
| 216 |
-
# Save outputs
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
|
| 221 |
return {"interpretations":interps, "sheets":sheets,
|
| 222 |
-
"agreement_rates":rates, "
|
|
|
|
| 223 |
|
| 224 |
# ---------------------------------------------------------------------------
|
| 225 |
# LangGraph node: build mismatch table
|
|
|
|
| 64 |
|
| 65 |
def _gemini(prompt, key):
|
| 66 |
if not key: return {}
|
| 67 |
+
for attempt in range(2):
|
| 68 |
+
try:
|
| 69 |
+
r = requests.post(
|
| 70 |
+
f"https://generativelanguage.googleapis.com/v1beta/models/"
|
| 71 |
+
f"gemini-2.5-flash:generateContent?key={key}",
|
| 72 |
+
headers={"Content-Type":"application/json"},
|
| 73 |
+
json={"contents":[{"parts":[{"text":prompt}]}],
|
| 74 |
+
"generationConfig":{"temperature":0.2}}, timeout=30)
|
| 75 |
+
d = r.json()
|
| 76 |
+
if "candidates" not in d:
|
| 77 |
+
logger.warning("Gemini attempt %d: no candidates: %s", attempt+1, d.get("error",""))
|
| 78 |
+
time.sleep(2); continue
|
| 79 |
+
return _parse(d["candidates"][0]["content"]["parts"][0]["text"])
|
| 80 |
+
except Exception as e:
|
| 81 |
+
logger.warning("Gemini attempt %d: %s", attempt+1, e)
|
| 82 |
+
time.sleep(2)
|
| 83 |
+
return {}
|
| 84 |
|
| 85 |
# ---------------------------------------------------------------------------
|
| 86 |
# Topic labelling prompt
|
|
|
|
| 219 |
"single": round((total - n_triple - n_two) / total * 100),
|
| 220 |
}
|
| 221 |
|
| 222 |
+
# Save outputs — 4 separate sheet files
|
| 223 |
+
sheet_paths = {}
|
| 224 |
+
names = {1:"sheet1_groq",2:"sheet2_mistral",3:"sheet3_gemini",4:"sheet4_consolidated"}
|
| 225 |
+
for sn, name in names.items():
|
| 226 |
+
path = f"{name}.csv"
|
| 227 |
+
pd.DataFrame(sheets[sn]).to_csv(path, index=False)
|
| 228 |
+
sheet_paths[sn] = path
|
| 229 |
+
with open("topics.json","w") as f: json.dump(sheets[4], f, indent=2)
|
| 230 |
|
| 231 |
return {"interpretations":interps, "sheets":sheets,
|
| 232 |
+
"agreement_rates":rates, "sheet_paths":sheet_paths,
|
| 233 |
+
"json_path":"topics.json"}
|
| 234 |
|
| 235 |
# ---------------------------------------------------------------------------
|
| 236 |
# LangGraph node: build mismatch table
|