Skip to content

Instantly share code, notes, and snippets.

@Darshan2104
Created November 16, 2022 05:54
Show Gist options
  • Save Darshan2104/e2113025ed375249d168b06fd2f53929 to your computer and use it in GitHub Desktop.
Save Darshan2104/e2113025ed375249d168b06fd2f53929 to your computer and use it in GitHub Desktop.
get paraphrased output in json format from nlu.md file
import pandas as pd
import json
# read nlu.md
# create a list of intent and it's nlus
# for each intent
# each nlu call api
# get result and store it
# store it into the new db
# seperate by space and check it line is empty or not !!!!!!
import requests
url = "http://172.16.22.5:7590/paraphraser"
f = open("nlu (12).md", 'r')
dict = {}
intent_name = ""
list_of_intents = []
for l in f.readlines():
flag = 1
if l != "":
s = l.split(' ')
s = ' '.join(s[1:])
s= s.strip("\n")
if ":" in s:
list_of_intents.append(s)
print(f"-------------------------------intent : {s}----------------------------------")
dict.setdefault(list_of_intents[-1], [])
flag = 0
if flag == 1:
# print(s)
# dict[list_of_intents[-1].strip("\n")].append(s.strip("\n"))
payload={'text': s}
files=[]
headers = {}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
j = json.loads(response.text)
list_of_list = j["para_phrases"]
if list_of_list is not None:
for l in list_of_list:
dict[list_of_intents[-1]].append(l[0])
else:
pass
else:
pass
f.close()
with open("sample.json", "w") as outfile:
json.dump(dict, outfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment