Spaces:
Runtime error
Runtime error
Add bonus contents (search results on the topic) & mini ToS
Browse filesFiles changed (7)
- .idea/slide-deck-ai.iml-4
- app.py+34-1
- global_config.py+2
- llm_helper.py+15-1
- pptx_helper.py+14-1
- requirements.txt+1
- strings.json+10-5
6 unmodified lines78910111213106 unmodified lines <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> </component> <component name="PyDocumentationSettings"> <option name="format" value="PLAIN" /> <option name="myDocStringFormat" value="Plain" /> </component></module>12345145 unmodified lines1511521531521541551561571581591601611 unmodified line163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195from typing import List
import json5import timeimport streamlit as st145 unmodified lines timestamp = time.time() output_file_name = f'{session_id}_{timestamp}.pptx'
pptx_helper.generate_powerpoint_presentation(json_str, as_yaml=False, output_file_name=output_file_name) all_headers = pptx_helper.generate_powerpoint_presentation( json_str, as_yaml=False, output_file_name=output_file_name ) progress_bar.progress(100, text='Done!')
# st.download_button('Download file', binary_contents) # Defaults to 'application/octet-stream'1 unmodified line with open(output_file_name, 'rb') as f: st.download_button('Download PPTX file', f, file_name=output_file_name)
show_bonus_stuff(all_headers)
st.divider() st.text(APP_TEXT['tos']) st.text(APP_TEXT['tos2'])
def show_bonus_stuff(ppt_headers: List): """ Show relevant links and images for the presentation topic.
:param ppt_headers: A list of all slide headers """
st.divider() st.header(APP_TEXT['section_headers'][3]) st.caption(APP_TEXT['section_captions'][3])
st.write(APP_TEXT['urls_info'])
# Use the presentation title and the slides headers to find relevant info online ppt_text = ' '.join(ppt_headers) search_results = llm_helper.get_related_websites(ppt_text)
for a_result in search_results.results: st.markdown(f'[{a_result.title}]({a_result.url})')
def button_clicked(button): """21 unmodified lines222324252627282921 unmodified lines LLM_MODEL_MAX_OUTPUT_LENGTH: int = 2000 LLM_MODEL_MAX_INPUT_LENGTH: int = 1000
METAPHOR_API_KEY = os.environ.get('METAPHOR_API_KEY', '')
APP_STRINGS_FILE = 'strings.json' PRELOAD_DATA_FILE = 'examples/example_02.json' SLIDES_TEMPLATE_FILE = 'langchain_templates/template_07.txt'12343 unmodified lines891011121314179 unmodified lines194195196197198199200201202203204205206196207208209210211import metaphor_python as metaphorfrom langchain import PromptTemplatefrom langchain.llms import Clarifai
3 unmodified linesprompt = Nonellm_contents = Nonellm_yaml = Nonemetaphor_client = None
def get_llm(use_gpt: bool) -> Clarifai:179 unmodified lines return output
def get_related_websites(query: str) -> metaphor.api.SearchResponse: global metaphor_client
if not metaphor_client: metaphor_client = metaphor.Metaphor(api_key=GlobalConfig.METAPHOR_API_KEY)
return metaphor_client.search(query, use_autoprompt=True, num_results=5)
if __name__ == '__main__': pass results = get_related_websites('5G AI WiFi 6')
for a_result in results.results: print(a_result.title, a_result.url, a_result.extract)
12341 unmodified line6789101112131415161718192021221 unmodified line24252619272829303132333435363717 unmodified lines555657585960619 unmodified lines7172737475767723 unmodified lines101102103104105106107108from typing import Listimport json5import pptximport re1 unmodified line
from pptx.dml.color import RGBColor
PATTERN = re.compile(r"^slide[ ]+\d+:", re.IGNORECASE)
def remove_slide_number_from_heading(header: str) -> str: """ Remove the slide number from a given slide header.
:param header: The header of a slide """
if PATTERN.match(header): idx = header.find(':') header = header[idx + 1:]1 unmodified line return header
def generate_powerpoint_presentation(structured_data: str, as_yaml: bool, output_file_name: str):def generate_powerpoint_presentation(structured_data: str, as_yaml: bool, output_file_name: str) -> List: """ Create and save a PowerPoint presentation file containing the contents in JSON or YAML format.
:param structured_data: The presentation contents as "JSON" (may contain trailing commas) or YAML :param as_yaml: True if the input data is in YAML format; False if it is in JSON format :param output_file_name: The name of the PPTX file to save as :return A list of presentation title and slides headers """
if as_yaml:17 unmodified lines title.text = parsed_data['title'] print(f'Title is: {title.text}') subtitle.text = 'by Myself and SlideDeck AI :)' all_headers = [title.text, ]
background = slide.background background.fill.solid()9 unmodified lines title_shape = shapes.title body_shape = shapes.placeholders[1] title_shape.text = remove_slide_number_from_heading(a_slide['heading']) all_headers.append(title_shape.text) text_frame = body_shape.text_frame
for an_item in a_slide['bullet_points']:23 unmodified lines
presentation.save(output_file_name)
return all_headers
if __name__ == '__main__': generate_powerpoint_presentation(4 unmodified lines56789104 unmodified linesclarifai==9.7.4
python-pptxmetaphor-pythonjson5~=0.9.14PyYAML~=6.0.14 unmodified lines567891010111211121314151615171819202122232422252627284 unmodified lines "Step 1: Generate your content", "Step 2: Make it structured", "Step 3: Create the slides", "Bonus Materials" ], "section_captions": [ "Let\'s start by generating some contents for your slides", "Let\'s now convert the above generated contents into JSON", "Let\'s now create the slides for you", "Let's start by generating some contents for your slides", "Let's now convert the above generated contents into JSON", "Let's now create the slides for you", "Wait, there's some more good stuff for you!" ], "input_labels": [ "**Describe the topic of the presentation. Avoid mentioning the count of slides.**\n*Note: the output may be short or truncated due to API limitations.*", "**Describe the topic of the presentation. Avoid mentioning the count of slides.**\n*Note: the output may be short or truncated due to API limitations.*" ], "button_labels": [ "Generate slides content", "Generate JSON", "Make the slides" ], "urls_info": "Here is a list of some online resources that you can consult for further information on this topic:", "content_generation_failure_error": "Unfortunately, SlideDeck AI failed to generate any content for you! Please try again later." "content_generation_failure_error": "Unfortunately, SlideDeck AI failed to generate any content for you! Please try again later.", "tos": "SlideDeck AI is an experimental prototype, and it has its limitations.\nPlease carefully review any and all AI-generated content.", "tos2": "By using SlideDeck AI, you agree to fair and responsible usage.\nNo liability assumed by any party."}.idea/slide-deck-ai.iml-4
app.py+34-1
global_config.py+2
llm_helper.py+15-1
pptx_helper.py+14-1
requirements.txt+1
strings.json+10-5