Skip to content

Commit

Permalink
FIX import tkinter only when using it to avoid import errors on ubunt…
Browse files Browse the repository at this point in the history
…u/macos (#542)
  • Loading branch information
romanlutz authored Nov 12, 2024
1 parent 6988eac commit 2dd5ff8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pyrit/score/human_in_the_loop_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Licensed under the MIT license.

import csv
import tkinter as tk
from tkinter import simpledialog

from pathlib import Path
from typing import Optional
Expand Down Expand Up @@ -177,6 +175,15 @@ async def score_async(self, request_response: PromptRequestPiece, *, task: Optio
return new_scores

def _get_user_input(self, message) -> str:
try:
import tkinter as tk
from tkinter import simpledialog
except ImportError as e:
print(
"To use HumanInTheLoopScorer, you need to install tkinter. "
"See https://stackoverflow.com/a/74607246 for more information."
)
raise e
root = tk.Tk()
root.withdraw()
user_input = simpledialog.askstring("Score Prompt", message).strip()
Expand Down

0 comments on commit 2dd5ff8

Please sign in to comment.