Spaces:
Sleeping
Sleeping
jedick commited on
Commit ·
d790ca4
1
Parent(s): 48c27bb
Update for Gradio 6
Browse filesFiles changed (2)
- app.py+63-86
- requirements.txt+1-1
179 unmodified lines1801811821831841851861871881891901911921931941953 unmodified lines19920020120220320420520620720820921021121221321421521615 unmodified lines23223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228376 unmodified lines36036136236336436536636736836937037135 unmodified lines40740840941041141241341441541641741841942042142242342442542642742842943043143243343414 unmodified lines449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478179 unmodified linesreturn run_classifier(old_revision, new_revision, prompt_style="few-shot")@logfire.instrument("Step 4: Run judge")def run_judge(old_revision: str,new_revision: str,heuristic_rationale,fewshot_rationale,judge_mode: str,):"""Run classification models and judge on the revisions.Args:old_revision: Old revision text3 unmodified linesjudge_mode: Mode for judge function ("unaligned", "aligned-fewshot", "aligned-heuristic")Returns:Tuple of (noteworthy, reasoning) (bool, str)"""# Values to return if there is an errornoteworthy, reasoning = None, Noneif (not old_revisionor not new_revisionor not heuristic_rationaleor not fewshot_rationale):return noteworthy, reasoningtry:# Run judge15 unmodified lineserror_msg = f"Error running judge: {str(e)}"raise gr.Error(error_msg, print_exception=False)return noteworthy, reasoningdef format_noteworthy(noteworthy, reasoning):"""Format judge's noteworthy label as text."""if not reasoning:# If the reasoning is empty, return nothingreturn Noneelse:# Format noteworthy boolean as textreturn str(noteworthy)def compute_confidence(heuristic_noteworthy,fewshot_noteworthy,judge_noteworthy,heuristic_rationale,fewshot_rationale,judge_reasoning,):"""Compute a confidence label using the noteworthy booleans."""# Return None if any of the rationales or reasoning is missing.if not heuristic_rationale or not fewshot_rationale or not judge_reasoning:return Noneif heuristic_noteworthy == fewshot_noteworthy == judge_noteworthy:# Classifiers and judge all agreereturn "High"elif heuristic_noteworthy != fewshot_noteworthy:# Classifiers disagree, judge decidesreturn "Moderate"else:# Classifiers agree, judge vetoesreturn "Questionable"# Setup theme without background imagetheme = gr.Theme.from_hub("NoCrypt/miku")theme.set(body_background_fill="#FFFFFF", body_background_fill_dark="#000000")# Create Gradio interfacewith gr.Blocks(theme=theme, title="Noteworthy Differences") as demo:with gr.Row():with gr.Column(scale=2):gr.Markdown(76 unmodified lineslines=1,interactive=False,)rerun_btn = gr.Button("Rerun Model", variant="primary")# Hidden checkboxes to store boolean valuesheuristic_noteworthy = gr.Checkbox(visible=False)fewshot_noteworthy = gr.Checkbox(visible=False)judge_noteworthy = gr.Checkbox(visible=False)random_btn.click(fn=get_random_wikipedia_title,35 unmodified linesinputs=[old_revision,new_revision,heuristic_rationale,fewshot_rationale,judge_mode_dropdown,],outputs=[judge_noteworthy, judge_reasoning],api_name=False,).then(fn=format_noteworthy,inputs=[judge_noteworthy, judge_reasoning],outputs=[noteworthy_text],api_name=False,).then(fn=compute_confidence,inputs=[heuristic_noteworthy,fewshot_noteworthy,judge_noteworthy,heuristic_rationale,fewshot_rationale,judge_reasoning,],outputs=[confidence],api_name=False,)14 unmodified linesinputs=[old_revision,new_revision,heuristic_rationale,fewshot_rationale,judge_mode_dropdown,],outputs=[judge_noteworthy, judge_reasoning],api_name=False,).then(fn=format_noteworthy,inputs=[judge_noteworthy, judge_reasoning],outputs=[noteworthy_text],api_name=False,).then(fn=compute_confidence,inputs=[heuristic_noteworthy,fewshot_noteworthy,judge_noteworthy,heuristic_rationale,fewshot_rationale,judge_reasoning,],outputs=[confidence],api_name=False,)if __name__ == "__main__":demo.launch()179 unmodified lines1801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212223 unmodified lines22622722822923023123223323423523623723823924024124224315 unmodified lines25926026126226326426526626726826927027127227327427527627727827928028128228328428576 unmodified lines36236336436536636736836937037137237335 unmodified lines40941041141241341441541641741841942042114 unmodified lines436437438439440441442443444445446447448449450451452453454455179 unmodified linesreturn run_classifier(old_revision, new_revision, prompt_style="few-shot")def compute_confidence(heuristic_noteworthy,fewshot_noteworthy,judge_noteworthy,heuristic_rationale,fewshot_rationale,judge_reasoning,):"""Compute a confidence label using the noteworthy booleans."""# Return None if any of the rationales or reasoning is missing.if not heuristic_rationale or not fewshot_rationale or not judge_reasoning:return Noneif heuristic_noteworthy == fewshot_noteworthy == judge_noteworthy:# Classifiers and judge all agreereturn "High"elif heuristic_noteworthy != fewshot_noteworthy:# Classifiers disagree, judge decidesreturn "Moderate"else:# Classifiers agree, judge vetoesreturn "Questionable"@logfire.instrument("Step 4: Run judge")def run_judge(old_revision: str,new_revision: str,heuristic_noteworthy: bool,fewshot_noteworthy: bool,heuristic_rationale: str,fewshot_rationale: str,judge_mode: str,):"""Run judge on the revisions and classifiers' rationales.Args:old_revision: Old revision text3 unmodified linesjudge_mode: Mode for judge function ("unaligned", "aligned-fewshot", "aligned-heuristic")Returns:Tuple of (noteworthy, noteworthy_text, reasoning, confidence) (bool, str, str, str)"""# Values to return if there is an errornoteworthy, noteworthy_text, reasoning, confidence = None, None, None, Noneif (not old_revisionor not new_revisionor not heuristic_rationaleor not fewshot_rationale):return noteworthy, noteworthy_text, reasoning, confidencetry:# Run judge15 unmodified lineserror_msg = f"Error running judge: {str(e)}"raise gr.Error(error_msg, print_exception=False)# Format noteworthy label (boolean) as textif not reasoning:noteworthy_text = Noneelse:noteworthy_text = str(noteworthy)# Get confidence scoreconfidence = compute_confidence(heuristic_noteworthy,fewshot_noteworthy,noteworthy,heuristic_rationale,fewshot_rationale,reasoning,)return noteworthy, noteworthy_text, reasoning, confidence# Create Gradio interfacewith gr.Blocks(title="Noteworthy Differences") as demo:with gr.Row():with gr.Column(scale=2):gr.Markdown(76 unmodified lineslines=1,interactive=False,)rerun_btn = gr.Button("Rerun Model")# States to store boolean valuesheuristic_noteworthy = gr.State()fewshot_noteworthy = gr.State()judge_noteworthy = gr.State()random_btn.click(fn=get_random_wikipedia_title,35 unmodified linesinputs=[old_revision,new_revision,heuristic_noteworthy,fewshot_noteworthy,heuristic_rationale,fewshot_rationale,judge_mode_dropdown,],outputs=[judge_noteworthy, noteworthy_text, judge_reasoning, confidence],api_name=False,)14 unmodified linesinputs=[old_revision,new_revision,heuristic_noteworthy,fewshot_noteworthy,heuristic_rationale,fewshot_rationale,judge_mode_dropdown,],outputs=[judge_noteworthy, noteworthy_text, judge_reasoning, confidence],api_name=False,)if __name__ == "__main__":# Setup theme without background imagetheme = gr.Theme.from_hub("NoCrypt/miku")theme.set(body_background_fill="#FFFFFF", body_background_fill_dark="#000000")demo.launch(theme=theme)
1 unmodified line23456781 unmodified linepydanticpandasdotenvgradiorequestslogfireopentelemetry-instrumentation-google-genai1 unmodified line23456781 unmodified linepydanticpandasdotenvgradio>=6.0.1requestslogfireopentelemetry-instrumentation-google-genai
app.py+63-86
requirements.txt+1-1