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 lines78910111213146 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>6 unmodified lines789106 unmodified lines<orderEntry type="inheritedJdk" /><orderEntry type="sourceFolder" forTests="false" /></component></module>
123145 unmodified lines1491501511521531541551 unmodified line157158159160161162import json5import timeimport streamlit as st145 unmodified linestimestamp = 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)progress_bar.progress(100, text='Done!')# st.download_button('Download file', binary_contents) # Defaults to 'application/octet-stream'1 unmodified linewith open(output_file_name, 'rb') as f:st.download_button('Download PPTX file', f, file_name=output_file_name)def button_clicked(button):"""12345145 unmodified lines1511521531541551561571581591601611 unmodified line163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195from typing import Listimport json5import timeimport streamlit as st145 unmodified linestimestamp = time.time()output_file_name = f'{session_id}_{timestamp}.pptx'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 linewith 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 onlineppt_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 lines22232425262721 unmodified linesLLM_MODEL_MAX_OUTPUT_LENGTH: int = 2000LLM_MODEL_MAX_INPUT_LENGTH: int = 1000APP_STRINGS_FILE = 'strings.json'PRELOAD_DATA_FILE = 'examples/example_02.json'SLIDES_TEMPLATE_FILE = 'langchain_templates/template_07.txt'21 unmodified lines222324252627282921 unmodified linesLLM_MODEL_MAX_OUTPUT_LENGTH: int = 2000LLM_MODEL_MAX_INPUT_LENGTH: int = 1000METAPHOR_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'
1233 unmodified lines789101112179 unmodified lines192193194195196197from langchain import PromptTemplatefrom langchain.llms import Clarifai3 unmodified linesprompt = Nonellm_contents = Nonellm_yaml = Nonedef get_llm(use_gpt: bool) -> Clarifai:179 unmodified linesreturn outputif __name__ == '__main__':pass12343 unmodified lines891011121314179 unmodified lines194195196197198199200201202203204205206207208209210211import metaphor_python as metaphorfrom langchain import PromptTemplatefrom langchain.llms import Clarifai3 unmodified linesprompt = Nonellm_contents = Nonellm_yaml = Nonemetaphor_client = Nonedef get_llm(use_gpt: bool) -> Clarifai:179 unmodified linesreturn outputdef get_related_websites(query: str) -> metaphor.api.SearchResponse:global metaphor_clientif 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__':results = get_related_websites('5G AI WiFi 6')for a_result in results.results:print(a_result.title, a_result.url, a_result.extract)
1231 unmodified line5678910111213141 unmodified line1617181920212223242526272817 unmodified lines4647484950519 unmodified lines61626364656623 unmodified lines909192939495import json5import pptximport re1 unmodified linefrom pptx.dml.color import RGBColorPATTERN = re.compile(r"^slide[ ]+\d+:", re.IGNORECASE)def remove_slide_number_from_heading(header: str) -> str:if PATTERN.match(header):idx = header.find(':')header = header[idx + 1:]1 unmodified linereturn headerdef generate_powerpoint_presentation(structured_data: str, as_yaml: bool, output_file_name: str):"""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"""if as_yaml:17 unmodified linestitle.text = parsed_data['title']print(f'Title is: {title.text}')subtitle.text = 'by Myself and SlideDeck AI :)'background = slide.backgroundbackground.fill.solid()9 unmodified linestitle_shape = shapes.titlebody_shape = shapes.placeholders[1]title_shape.text = remove_slide_number_from_heading(a_slide['heading'])text_frame = body_shape.text_framefor an_item in a_slide['bullet_points']:23 unmodified linespresentation.save(output_file_name)if __name__ == '__main__':generate_powerpoint_presentation(12341 unmodified line6789101112131415161718192021221 unmodified line242526272829303132333435363717 unmodified lines555657585960619 unmodified lines7172737475767723 unmodified lines101102103104105106107108from typing import Listimport json5import pptximport re1 unmodified linefrom pptx.dml.color import RGBColorPATTERN = 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 linereturn headerdef 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 linestitle.text = parsed_data['title']print(f'Title is: {title.text}')subtitle.text = 'by Myself and SlideDeck AI :)'all_headers = [title.text, ]background = slide.backgroundbackground.fill.solid()9 unmodified linestitle_shape = shapes.titlebody_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_framefor an_item in a_slide['bullet_points']:23 unmodified linespresentation.save(output_file_name)return all_headersif __name__ == '__main__':generate_powerpoint_presentation(
4 unmodified lines567894 unmodified linesclarifai==9.7.4python-pptxjson5~=0.9.14PyYAML~=6.0.14 unmodified lines56789104 unmodified linesclarifai==9.7.4python-pptxmetaphor-pythonjson5~=0.9.14PyYAML~=6.0.1
4 unmodified lines5678910111213141516171819202122234 unmodified lines"Step 1: Generate your content","Step 2: Make it structured","Step 3: Create the slides",],"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",],"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.*",],"button_labels": ["Generate slides content","Generate JSON","Make the slides"],"content_generation_failure_error": "Unfortunately, SlideDeck AI failed to generate any content for you! Please try again later."}4 unmodified lines56789101112131415161718192021222324252627284 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","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.*"],"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.","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