| import gradio as gr |
| import subprocess |
| import spaces |
| import os |
| import json |
|
|
| |
| os.makedirs('./eval_results', exist_ok=True) |
|
|
| def run_evaluation(): |
| |
| hf_token = os.environ.get("HF_TOKEN", "") |
| |
| if not hf_token: |
| yield "β οΈ Warning: HF_TOKEN secret not found. Attempting unauthenticated access..." |
| else: |
| yield "π Authenticating terminal session with HF_TOKEN..." |
| subprocess.run(["huggingface-cli", "login", "--token", hf_token], capture_output=True) |
| yield "β
Authentication successful." |
|
|
| tasks = "mmlu,gsm8k,winogrande" |
| output_file = "./eval_results/results.json" |
| |
| |
| command = [ |
| "lm_eval", |
| "--model", "hf", |
| "--model_args", "pretrained=Girikannan/sarvam-eval,device_map=auto,trust_remote_code=True", |
| "--device", "cuda", |
| "--tasks", tasks, |
| "--batch_size", "1", |
| "--output_path", output_file |
| ] |
| |
| yield "π Initializing evaluation on GPU... (The model is already downloaded and cached, so this will boot up fast!)" |
| |
| try: |
| process = subprocess.run(command, capture_output=True, text=True) |
| |
| if process.returncode == 0: |
| with open(output_file, 'r') as f: |
| results = json.load(f) |
| yield f"π― Evaluation Complete!\n\nResults: {json.dumps(results, indent=2)}" |
| else: |
| yield f"β Evaluation failed with error:\n{process.stderr}" |
| |
| except Exception as e: |
| yield f"π¨ An unexpected error occurred: {str(e)}" |
| |
|
|
| |
| with gr.Blocks() as demo: |
| gr.Markdown("# Sarvam-30b Compression Evaluator") |
| gr.Markdown("Click the button below to run the evaluation suite.") |
| |
| eval_button = gr.Button("Start Full Evaluation") |
| output_text = gr.Textbox(label="Evaluation Log", lines=20) |
| |
| run_eval_gpu = spaces.GPU(duration=3600)(run_evaluation) |
| eval_button.click(run_eval_gpu, inputs=None, outputs=output_text) |
|
|
| if __name__ == "__main__": |
| demo.launch() |