Skip to content

Commit

Permalink
Added a Report Generator to the Shuffle AI app
Browse files Browse the repository at this point in the history
  • Loading branch information
frikky committed Aug 24, 2023
1 parent d91fc5c commit ecf655f
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
34 changes: 34 additions & 0 deletions shuffle-ai/1.0.0/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,40 @@ actions:
returns:
schema:
type: string
- name: generate_report
description: Input ANY kind of data in the format you want, and it will make an HTML report for you. This can be downloaded from the File location.
parameters:
- name: apikey
description: Your https://shuffler.io apikey
required: true
multiline: false
example: ""
schema:
type: string
- name: input_data
description: The text you want to be converted (ANY format)
required: true
multiline: true
example: "Bad IPs are 1.2.3.4 and there's no good way to format this. JSON works too!"
schema:
type: string
- name: report_title
description: The report title to be used in the report
required: true
multiline: true
example: "Statistics for October"
schema:
type: string
- name: report_name
description: The name of the HTML file
required: false
multiline: true
example: "statistics.html"
schema:
type: string
returns:
schema:
type: string
- name: extract_text_from_pdf
description: Returns text from a pdf
parameters:
Expand Down
53 changes: 53 additions & 0 deletions shuffle-ai/1.0.0/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,59 @@ def autoformat_text(self, apikey, text, formatting="auto"):

return ret.text

def generate_report(self, apikey, input_data, report_title, report_name="generated_report.html"):
headers = {
"Authorization": "Bearer %s" % apikey,
}

if not report_name:
report_name = "generated_report.html"

if "." in report_name and not ".html" in report_name:
report_name = report_name.split(".")[0]

if not "html" in report_name:
report_name = report_name + ".html"

report_name = report_name.replace(" ", "_", -1)

if not formatting:
formatting = "auto"

output_formatting= "Format the following text into an HTML report with relevant graphs and tables. Title of the report should be {report_title}."
ret = requests.post(
"https://shuffler.io/api/v1/conversation",
json={
"query": text,
"formatting": output_formatting,
"output_format": "formatting"
},
headers=headers,
)

if ret.status_code != 200:
print(ret.text)
return {
"success": False,
"reason": "Status code for auto-formatter is not 200"
}

# Make it into a shuffle file with self.set_files()
new_file = {
"name": report_name,
"data": ret.text,
}

retdata = self.set_files([new_file])
if retdata["success"]:
return retdata

return {
"success": False,
"reason": "Failed to upload file"
}


def extract_text_from_pdf(self, file_id):
def extract_pdf_text(pdf_path):
with open(pdf_path, 'rb') as file:
Expand Down
6 changes: 6 additions & 0 deletions shuffle-ai/1.0.0/upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

gcloud run deploy shuffle-ai-1-0-0 \
--region=europe-west2 \
--max-instances=3 \
--set-env-vars=SHUFFLE_APP_EXPOSED_PORT=8080,SHUFFLE_SWARM_CONFIG=run,SHUFFLE_LOGS_DISABLED=true --source=./ \
--timeout=1800s

0 comments on commit ecf655f

Please sign in to comment.