Sending a dataframe of Arabic text to Farasa API for lemmatization - what am I doing wrong?

63 Views Asked by At

How can I send a dataframe that consists of thousands of rows to API lemmatization webpage using this code anyone can help me

import json
import http.client

text = df[reviews]
conn = http.client.HTTPSConnection("farasa-api.qcri.org")
payload = "{\"text\":\"%s\"}"% text
payload = payload.encode('utf-8')

headers = { 'content-type': "application/json", 'cache-control': "no-cache", }

conn.request("POST", "/msa/webapi/lemma", payload, headers)

res = conn.getresponse()

data = res.read().decode('utf-8')
data_dict = json.loads(data)

I try to convert csv file to json file and send it to the api but still doesn't work and appear this type of error:

JSONDecodeError: Expecting value: line 1 column 1 (char 0)`

this is what I try to do :

df_json= json.loads(df['review'].to_json(orient='records'))

import json
import http.client

text = df_json
conn = http.client.HTTPSConnection("farasa-api.qcri.org")
payload = "{\"text\":\"%s\"}"% text
payload = payload.encode('utf-8')

headers = { 'content-type': "application/json", 'cache-control': "no-cache", }

conn.request("POST", "/msa/webapi/lemma", payload, headers)

res = conn.getresponse()

data = res.read().decode('utf-8')
data_dict = json.loads(data)
0

There are 0 best solutions below