Downloads · 30 days
0
Thatchan/Pdf_Ai_query_answerer
Pdf_Ai_query_answerer is a machine learning model from Thatchan. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
import os import requests import re import json
Downloads · 30 days
0
Access
Public
Updated Aug 23, 2024
Repo size
—
Likes
0
Public
Click a slice to open those files.
.md1.9 KB · 55%
From the Hugging Face model README
import os import requests import re import json
apiKey = "d5eccb08-002a-4d34-aad6-8834a8692caf"
def query_api(usersInputObj): inputsArray = [ {"id": "{input_1}", "label": "Enter query", "type": "text"}, {"id": "{input_2}", "label": "Upload a pdf file", "type": "file"} ]
prompt = "Answer this query {input_1} from this pdf file url {input_2}"
filesData, textData = {}, {}
for inputObj in inputsArray:
inputId = inputObj['id']
if inputObj['type'] == 'text':
prompt = prompt.replace(inputId, usersInputObj[inputId])
elif inputObj['type'] == 'file':
path = usersInputObj[inputId]
file_name = os.path.basename(path)
f = open(path, 'rb')
filesData[inputId] = f
textData['details'] = json.dumps({
'appname': 'pdf ai query answerer',
'prompt': prompt,
'documentId': 'no-embd-type',
'appId': '66c8aae064d827b744a2a12d',
'memoryId': '',
'apiKey': apiKey
})
response = requests.post('https://apiappstore.guvi.ai/api/output', data=textData, files=filesData)
output = response.json()
# Close the file after use
if filesData:
for file in filesData.values():
file.close()
return output['output']
def predict(inputs): # Prepare the input object for API usersInputObj = { '{input_1}': inputs.get("input_1", ""), '{input_2}': inputs.get("input_2", "") }
# Call the query API function
output = query_api(usersInputObj)
# Replace the localhost URL with the correct one
url_regex = r'http://localhost:7000/'
replaced_string = re.sub(url_regex, 'https://apiappstore.guvi.ai/', output)
# Return the final output
return {"output": replaced_string}