Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Adding cached_path to input file of the predictor (#3098)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldeutsch authored and matt-gardner committed Jul 29, 2019
1 parent 417a757 commit 0caf364
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions allennlp/commands/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

from allennlp.commands.subcommand import Subcommand
from allennlp.common.checks import check_for_gpu, ConfigurationError
from allennlp.common.file_utils import cached_path
from allennlp.common.util import lazy_groups_of
from allennlp.models.archival import load_archive
from allennlp.predictors.predictor import Predictor, JsonDict
Expand All @@ -68,7 +69,7 @@ def add_subparser(self, name: str, parser: argparse._SubParsersAction) -> argpar
name, description=description, help='Use a trained model to make predictions.')

subparser.add_argument('archive_file', type=str, help='the archived model to make predictions with')
subparser.add_argument('input_file', type=str, help='path to input file')
subparser.add_argument('input_file', type=str, help='path to or url of the input file')

subparser.add_argument('--output-file', type=str, help='path to output file')
subparser.add_argument('--weights-file',
Expand Down Expand Up @@ -177,7 +178,8 @@ def _get_json_data(self) -> Iterator[JsonDict]:
if not line.isspace():
yield self._predictor.load_line(line)
else:
with open(self._input_file, "r") as file_input:
input_file = cached_path(self._input_file)
with open(input_file, "r") as file_input:
for line in file_input:
if not line.isspace():
yield self._predictor.load_line(line)
Expand Down

0 comments on commit 0caf364

Please sign in to comment.