Spaces:
Sleeping
Sleeping
Download src/comparison.py from BrainDrive/Summary-Evaluator: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/BrainDrive/Summary-Evaluator/resolve/main/src/comparison.py
- Command line
-
hf download hf://spaces/BrainDrive/Summary-Evaluator/src/comparison.py
-
curl -L -o comparison.py https://huggingface.co/spaces/BrainDrive/Summary-Evaluator/resolve/main/src/comparison.py
1.13 kB
| import json | |
| from src.api_clients import openai_client | |
| last_eval_result = {} # Shared state | |
| def get_last_eval_data(): | |
| return last_eval_result if last_eval_result else None | |
| def run_comparison(human_scores, human_comments, model_scores, model_comments): | |
| prompt = f"""Compare human and model summary evaluations. | |
| Human Scores: {human_scores} | |
| Model Scores: {model_scores} | |
| Human Comments: {human_comments} | |
| Model Comments: {model_comments} | |
| Output key differences, strengths, and any mismatches.""" | |
| res = openai_client.chat.completions.create( | |
| model="gpt-4o-mini", | |
| messages=[{"role": "user", "content": prompt}], | |
| max_tokens=800 | |
| ) | |
| return res.choices[0].message.content | |
| def import_model_metrics(): | |
| data = get_last_eval_data() | |
| if not data or "scores" not in data: | |
| return ["" ] * 6 | |
| s = data["scores"] | |
| return ( | |
| str(s.get("coverage", "")), | |
| str(s.get("alignment", "")), | |
| str(s.get("hallucination", "")), | |
| str(s.get("relevance", "")), | |
| str(s.get("bias_toxicity", "")), | |
| json.dumps(data.get("comments", ""), indent=2) | |
| ) |