#!/usr/bin/env python3 """Manual ORCA6 feedback intake Space.""" from __future__ import annotations import json import os from pathlib import Path import gradio as gr from feedback_records import append_jsonl, build_feedback_record DEFAULT_OUTPUT = Path(os.environ.get("ORCA6_FEEDBACK_OUTPUT", "feedback/space_feedback_v0.1-rc1.jsonl")) def save_feedback( prompt: str, tester_prompt_id: str, model_answer: str, retrieved_sources: str, rating: str, issue_type: str, correction: str, model_version: str, review_notes: str, include_in_training: bool, secrets_checked: bool, ) -> tuple[str, str]: try: row = build_feedback_record( prompt=prompt, tester_prompt_id=tester_prompt_id, model_answer=model_answer, retrieved_sources=retrieved_sources, rating=rating, issue_type=issue_type, correction=correction, model_version=model_version, review_notes=review_notes, include_in_training=include_in_training, secrets_checked=secrets_checked, source="huggingface_space", ) except ValueError as exc: return str(exc), "" append_jsonl(DEFAULT_OUTPUT, row) return f"Saved feedback to {DEFAULT_OUTPUT}", json.dumps(row, indent=2, ensure_ascii=False) with gr.Blocks(title="ORCA6 Feedback") as demo: gr.Markdown("# ORCA6 Feedback") with gr.Row(): model_version = gr.Textbox(label="Model version", value="v0.1-rc1") rating = gr.Radio(["useful", "mixed", "not useful"], label="Rating", value="mixed") issue_type = gr.Dropdown( [ "no issue", "hallucination", "missing tool", "too complex", "too generic", "unsafe", "outdated", "citation/source problem", ], label="Issue type", value="no issue", ) prompt = gr.Textbox(label="Prompt", lines=5) tester_prompt_id = gr.Textbox(label="Tester prompt ID", placeholder="tester-001") model_answer = gr.Textbox(label="Model answer", lines=8) retrieved_sources = gr.Textbox(label="Retrieved sources", lines=5, placeholder="(no retrieved evidence)") correction = gr.Textbox(label="Suggested correction", lines=6) review_notes = gr.Textbox(label="Reviewer notes", lines=4) with gr.Row(): include_in_training = gr.Checkbox(label="Approved for possible training after review") secrets_checked = gr.Checkbox(label="Checked for secrets/private data") submit = gr.Button("Save feedback", variant="primary") status = gr.Textbox(label="Status", interactive=False) saved_json = gr.Code(label="Saved row", language="json") submit.click( save_feedback, inputs=[ prompt, tester_prompt_id, model_answer, retrieved_sources, rating, issue_type, correction, model_version, review_notes, include_in_training, secrets_checked, ], outputs=[status, saved_json], ) if __name__ == "__main__": demo.launch()