Spaces:
Running
Running
Merge branch 'main' of github.com:barun-saha/slide-deck-ai
Browse files- app.py +0 -1
- clarifai_grpc_helper.py +0 -71
- pptx_helper.py +6 -18
- requirements.txt +0 -3
app.py
CHANGED
|
@@ -260,7 +260,6 @@ def generate_slide_deck(json_str: str, pptx_template: str, progress_bar) -> List
|
|
| 260 |
logging.info('Creating PPTX file...')
|
| 261 |
all_headers = pptx_helper.generate_powerpoint_presentation(
|
| 262 |
json_str,
|
| 263 |
-
as_yaml=False,
|
| 264 |
slides_template=pptx_template,
|
| 265 |
output_file_path=path
|
| 266 |
)
|
|
|
|
| 260 |
logging.info('Creating PPTX file...')
|
| 261 |
all_headers = pptx_helper.generate_powerpoint_presentation(
|
| 262 |
json_str,
|
|
|
|
| 263 |
slides_template=pptx_template,
|
| 264 |
output_file_path=path
|
| 265 |
)
|
clarifai_grpc_helper.py
DELETED
|
@@ -1,71 +0,0 @@
|
|
| 1 |
-
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
|
| 2 |
-
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
|
| 3 |
-
from clarifai_grpc.grpc.api.status import status_code_pb2
|
| 4 |
-
|
| 5 |
-
from global_config import GlobalConfig
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
CHANNEL = ClarifaiChannel.get_grpc_channel()
|
| 9 |
-
STUB = service_pb2_grpc.V2Stub(CHANNEL)
|
| 10 |
-
|
| 11 |
-
METADATA = (
|
| 12 |
-
('authorization', 'Key ' + GlobalConfig.CLARIFAI_PAT),
|
| 13 |
-
)
|
| 14 |
-
|
| 15 |
-
USER_DATA_OBJECT = resources_pb2.UserAppIDSet(
|
| 16 |
-
user_id=GlobalConfig.CLARIFAI_USER_ID,
|
| 17 |
-
app_id=GlobalConfig.CLARIFAI_APP_ID
|
| 18 |
-
)
|
| 19 |
-
|
| 20 |
-
RAW_TEXT = '''You are a helpful, intelligent chatbot. Create the slides for a presentation on the given topic. Include main headings for each slide, detailed bullet points for each slide. Add relevant content to each slide. Do not output any blank line.
|
| 21 |
-
|
| 22 |
-
Topic:
|
| 23 |
-
Talk about AI, covering what it is and how it works. Add its pros, cons, and future prospects. Also, cover its job prospects.
|
| 24 |
-
'''
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
def get_text_from_llm(prompt: str) -> str:
|
| 28 |
-
post_model_outputs_response = STUB.PostModelOutputs(
|
| 29 |
-
service_pb2.PostModelOutputsRequest(
|
| 30 |
-
user_app_id=USER_DATA_OBJECT, # The userDataObject is created in the overview and is required when using a PAT
|
| 31 |
-
model_id=GlobalConfig.CLARIFAI_MODEL_ID,
|
| 32 |
-
# version_id=MODEL_VERSION_ID, # This is optional. Defaults to the latest model version
|
| 33 |
-
inputs=[
|
| 34 |
-
resources_pb2.Input(
|
| 35 |
-
data=resources_pb2.Data(
|
| 36 |
-
text=resources_pb2.Text(
|
| 37 |
-
raw=prompt
|
| 38 |
-
)
|
| 39 |
-
)
|
| 40 |
-
)
|
| 41 |
-
]
|
| 42 |
-
),
|
| 43 |
-
metadata=METADATA
|
| 44 |
-
)
|
| 45 |
-
|
| 46 |
-
if post_model_outputs_response.status.code != status_code_pb2.SUCCESS:
|
| 47 |
-
print(post_model_outputs_response.status)
|
| 48 |
-
raise Exception(f"Post model outputs failed, status: {post_model_outputs_response.status.description}")
|
| 49 |
-
|
| 50 |
-
# Since we have one input, one output will exist here
|
| 51 |
-
output = post_model_outputs_response.outputs[0]
|
| 52 |
-
|
| 53 |
-
# print("Completion:\n")
|
| 54 |
-
# print(output.data.text.raw)
|
| 55 |
-
|
| 56 |
-
return output.data.text.raw
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
if __name__ == '__main__':
|
| 60 |
-
topic = ('Talk about AI, covering what it is and how it works.'
|
| 61 |
-
' Add its pros, cons, and future prospects.'
|
| 62 |
-
' Also, cover its job prospects.'
|
| 63 |
-
)
|
| 64 |
-
print(topic)
|
| 65 |
-
|
| 66 |
-
with open(GlobalConfig.SLIDES_TEMPLATE_FILE, 'r') as in_file:
|
| 67 |
-
prompt_txt = in_file.read()
|
| 68 |
-
prompt_txt = prompt_txt.replace('{topic}', topic)
|
| 69 |
-
response_txt = get_text_from_llm(prompt_txt)
|
| 70 |
-
|
| 71 |
-
print('Output:\n', response_txt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pptx_helper.py
CHANGED
|
@@ -6,7 +6,6 @@ from typing import List, Tuple
|
|
| 6 |
|
| 7 |
import json5
|
| 8 |
import pptx
|
| 9 |
-
import yaml
|
| 10 |
|
| 11 |
from global_config import GlobalConfig
|
| 12 |
|
|
@@ -51,31 +50,20 @@ def remove_slide_number_from_heading(header: str) -> str:
|
|
| 51 |
|
| 52 |
def generate_powerpoint_presentation(
|
| 53 |
structured_data: str,
|
| 54 |
-
as_yaml: bool,
|
| 55 |
slides_template: str,
|
| 56 |
output_file_path: pathlib.Path
|
| 57 |
) -> List:
|
| 58 |
"""
|
| 59 |
-
Create and save a PowerPoint presentation file containing the
|
| 60 |
|
| 61 |
-
:param structured_data: The presentation contents as "JSON" (may contain trailing commas)
|
| 62 |
-
YAML
|
| 63 |
-
:param as_yaml: True if the input data is in YAML format; False if it is in JSON format
|
| 64 |
:param slides_template: The PPTX template to use
|
| 65 |
:param output_file_path: The path of the PPTX file to save as
|
| 66 |
:return A list of presentation title and slides headers
|
| 67 |
"""
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
try:
|
| 72 |
-
parsed_data = yaml.safe_load(structured_data)
|
| 73 |
-
except yaml.parser.ParserError as ype:
|
| 74 |
-
logging.error('*** YAML parse error: %s', str(ype))
|
| 75 |
-
parsed_data = {'title': '', 'slides': []}
|
| 76 |
-
else:
|
| 77 |
-
# The structured "JSON" might contain trailing commas, so using json5
|
| 78 |
-
parsed_data = json5.loads(structured_data)
|
| 79 |
|
| 80 |
logging.debug(
|
| 81 |
"*** Using PPTX template: %s",
|
|
@@ -134,7 +122,8 @@ def generate_powerpoint_presentation(
|
|
| 134 |
|
| 135 |
def get_flat_list_of_contents(items: list, level: int) -> List[Tuple]:
|
| 136 |
"""
|
| 137 |
-
Flatten a (hierarchical) list of bullet points to a single list containing each item and
|
|
|
|
| 138 |
|
| 139 |
:param items: A bullet point (string or list)
|
| 140 |
:param level: The current level of hierarchy
|
|
@@ -248,7 +237,6 @@ if __name__ == '__main__':
|
|
| 248 |
|
| 249 |
generate_powerpoint_presentation(
|
| 250 |
json5.loads(json_data),
|
| 251 |
-
as_yaml=False,
|
| 252 |
output_file_path=path,
|
| 253 |
slides_template='Blank'
|
| 254 |
)
|
|
|
|
| 6 |
|
| 7 |
import json5
|
| 8 |
import pptx
|
|
|
|
| 9 |
|
| 10 |
from global_config import GlobalConfig
|
| 11 |
|
|
|
|
| 50 |
|
| 51 |
def generate_powerpoint_presentation(
|
| 52 |
structured_data: str,
|
|
|
|
| 53 |
slides_template: str,
|
| 54 |
output_file_path: pathlib.Path
|
| 55 |
) -> List:
|
| 56 |
"""
|
| 57 |
+
Create and save a PowerPoint presentation file containing the content in JSON format.
|
| 58 |
|
| 59 |
+
:param structured_data: The presentation contents as "JSON" (may contain trailing commas)
|
|
|
|
|
|
|
| 60 |
:param slides_template: The PPTX template to use
|
| 61 |
:param output_file_path: The path of the PPTX file to save as
|
| 62 |
:return A list of presentation title and slides headers
|
| 63 |
"""
|
| 64 |
|
| 65 |
+
# The structured "JSON" might contain trailing commas, so using json5
|
| 66 |
+
parsed_data = json5.loads(structured_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
logging.debug(
|
| 69 |
"*** Using PPTX template: %s",
|
|
|
|
| 122 |
|
| 123 |
def get_flat_list_of_contents(items: list, level: int) -> List[Tuple]:
|
| 124 |
"""
|
| 125 |
+
Flatten a (hierarchical) list of bullet points to a single list containing each item and
|
| 126 |
+
its level.
|
| 127 |
|
| 128 |
:param items: A bullet point (string or list)
|
| 129 |
:param level: The current level of hierarchy
|
|
|
|
| 237 |
|
| 238 |
generate_powerpoint_presentation(
|
| 239 |
json5.loads(json_data),
|
|
|
|
| 240 |
output_file_path=path,
|
| 241 |
slides_template='Blank'
|
| 242 |
)
|
requirements.txt
CHANGED
|
@@ -2,11 +2,8 @@ python-dotenv[cli]~=1.0.0
|
|
| 2 |
langchain~=0.1.13
|
| 3 |
# huggingface_hub
|
| 4 |
streamlit~=1.32.2
|
| 5 |
-
clarifai==9.7.4
|
| 6 |
|
| 7 |
python-pptx
|
| 8 |
metaphor-python
|
| 9 |
json5~=0.9.14
|
| 10 |
-
PyYAML~=6.0.1
|
| 11 |
-
# curlify
|
| 12 |
requests~=2.31.0
|
|
|
|
| 2 |
langchain~=0.1.13
|
| 3 |
# huggingface_hub
|
| 4 |
streamlit~=1.32.2
|
|
|
|
| 5 |
|
| 6 |
python-pptx
|
| 7 |
metaphor-python
|
| 8 |
json5~=0.9.14
|
|
|
|
|
|
|
| 9 |
requests~=2.31.0
|