skip to Main Content

I am trying to learn the use of gravityai and frankly i am a bit new to this. For that i followed https://www.youtube.com/watch?v=i6qL3NqFjs4 from Ania Kubow. When i do this, at the end i encounter the error message. This message appears in gravity ai, when trying to run the job, i.e. after uploading all zipped files three .pkl files, one .py file, one .txt file, one .json file), after docker is initialized and run:

Error running executable: usage: classify_financial_articles.py [-h] {run,serve} ... classify_financial_articles.py: error: argument subcommand: invalid choice: '/tmp/gai_temp/0675f15ca0b04cf98071474f19e38f3c/76f5cdc86a1241af8c01ce1b4d441b0c' (choose from 'run', 'serve').

I do not understand the error message and therefore cannot fix it. Is it an error in the code? or in the configuration on the gravityai platform? At no point do i run the .py file explicitly so i conclude, that it must be from the gravityai. Yet i dont get the error. Can anyone help me?

i added the .py file, as it is the one throwing the error

from gravityai import gravityai as grav
import pickle
import pandas as pd

model = pickle.load(open('financial_text_classifier.pkl', 'rb'))
tfidf_vectorizer = pickle.load(open('financial_text_vectorizer.pkl','rb'))
label_encder = pickle.load(open('financial_text_encoder.pkl', 'rb'))

def process(inPath, outPath):
    # read csv input  file
    input_df = pd.read_csv(inPath)
    # read the data
    features = tfidf_vectorizer.transform(input_df['body'])
    # predict classes
    predictions = model.predict(features)
    #convert outpulabels to categories
    input_df['category'] = label_encder.inverse_transform(predictions)
    #save results to csv
    output_df = input_df(['id', 'category'])
    output_df.csv(outPath, index=False)

    grav.wait_for_requests(process) 

I can’t find any errors in the .py file

2

Answers


  1. The error you got comes from the line that imports gravityai library:

    from gravityai import gravityai as grav
    

    I believe you need to upload your projet to the gravityai platform and then you will be able to test it

    Login or Signup to reply.
  2. To test localy you need to:

    1)Add line"import sys".

    2)Comment or delete line"grav.wait_for_requests(process)"

    3)Add line: "process(inPath=sys.argv[2], outPath=sys.argv[3])".

    4)Run from command line "python classify_financial_articles.py run test_set.csv test_set_out.csv"

    Example of code:

    from gravityai import gravityai as grav
    import pickle
    import pandas as pd
    import sys
    
    model = pickle.load(open('financial_text_clasifier.pkl', 'rb'))
    tfidf_vectorizer = pickle.load(open('financial_text_vectorizer.pkl', 'rb'))
    label_encoder = pickle.load(open('financial_text_encoder.pkl', 'rb'))
    
    def process(inPath, outPath):
        input_df = pd.read_csv(inPath)
        features = tfidf_vectorizer.transform(input_df['body'])
        predictions = model.predict(features)
        input_df['category'] = label_encoder.inverse_transform(predictions)
        output_df = input_df[['id', 'category']]
        output_df.to_csv(outPath, index=False)
    
    process(inPath=sys.argv[2], outPath=sys.argv[3])
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search