@@ -48,8 +48,10 @@ def main():
48
48
logging .basicConfig (level = logging .INFO , format = "%(asctime)s - %(levelname)s - %(message)s" )
49
49
50
50
parser = argparse .ArgumentParser (description = "Convert documents to Markdown." )
51
- parser .add_argument ("input_file" , help = "Path to the input document (PDF, Word, etc.)" )
52
- parser .add_argument ("-o" , "--output-dir" , required = True , help = "Directory to save the converted Markdown file" )
51
+ input_group = parser .add_mutually_exclusive_group (required = True )
52
+ input_group .add_argument ("--input-file" , help = "Path to the input document (PDF, Word, etc.)" )
53
+ input_group .add_argument ("--input-dir" , help = "Path to a directory containing supported documents" )
54
+ parser .add_argument ("-o" , "--output-dir" , required = True , help = "Directory to save the converted Markdown file(s)" )
53
55
parser .add_argument ("--insert-into-llm" , action = "store_true" , help = "Insert output into LLM" )
54
56
55
57
args = parser .parse_args ()
@@ -66,14 +68,15 @@ def main():
66
68
ensure_env_variable ("OPENAI_API_KEY" , "Enter your OpenAI API key: " )
67
69
ensure_env_variable ("OPENAI_MODEL" , "Enter OpenAI model name (default: gpt-4): " , default = "gpt-4" )
68
70
69
- # Run conversion
71
+ # Run conversion for either a single file or a directory
70
72
markitdown = MarkItDown (args .output_dir )
71
- markitdown .convert_document (args .input_file , args .insert_into_llm )
73
+
74
+ if args .input_file :
75
+ markitdown .convert_document (args .input_file , args .insert_into_llm )
76
+ elif args .input_dir :
77
+ markitdown .convert_directory (args .input_dir , args .insert_into_llm )
72
78
73
79
except Exception as e :
74
80
logging .error (f"Error: { e } " , exc_info = True )
75
81
sys .exit (1 )
76
82
77
-
78
- if __name__ == "__main__" :
79
- main ()
0 commit comments