├── .gitignore ├── LICENSE ├── README.md ├── app.py ├── fetch_image.py ├── requirements.txt └── sample.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 AI Anytime 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Llama2-PPT-Generation-App 2 | This is an official repository for the PPT Generation app using Llama2, Python-pptx, Pexels, and Streamlit. 3 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from langchain.llms import CTransformers 2 | from langchain.chains import LLMChain 3 | from langchain import PromptTemplate 4 | import streamlit as st 5 | import os 6 | from docx import Document 7 | from docx.shared import Inches 8 | import io 9 | from PIL import Image 10 | import requests 11 | 12 | #Loading the model 13 | def load_llm(max_tokens, prompt_template): 14 | # Load the locally downloaded model here 15 | llm = CTransformers( 16 | model = "llama-2-7b-chat.ggmlv3.q8_0.bin", 17 | model_type="llama", 18 | max_new_tokens = max_tokens, 19 | temperature = 0.7 20 | ) 21 | 22 | llm_chain = LLMChain( 23 | llm=llm, 24 | prompt=PromptTemplate.from_template(prompt_template) 25 | ) 26 | print(llm_chain) 27 | return llm_chain 28 | 29 | def get_src_original_url(query): 30 | url = 'https://api.pexels.com/v1/search' 31 | headers = { 32 | 'Authorization': "iMn2jjJXgPCqmalZsrDxYA5WcLSyt1FgopsBxY4M8rUxRc4POC83rsR3", 33 | } 34 | 35 | params = { 36 | 'query': query, 37 | 'per_page': 1, 38 | } 39 | 40 | response = requests.get(url, headers=headers, params=params) 41 | 42 | # Check if the request was successful (status code 200) 43 | if response.status_code == 200: 44 | data = response.json() 45 | photos = data.get('photos', []) 46 | if photos: 47 | src_original_url = photos[0]['src']['original'] 48 | return src_original_url 49 | else: 50 | st.write("No photos found for the given query.") 51 | else: 52 | st.write(f"Error: {response.status_code}, {response.text}") 53 | 54 | return None 55 | 56 | def create_word_docx(user_input, paragraph, image_input): 57 | # Create a new Word document 58 | doc = Document() 59 | 60 | # Add the user input to the document 61 | doc.add_heading(user_input, level=1) 62 | doc.add_paragraph(paragraph) 63 | 64 | # Add the image to the document 65 | doc.add_heading('Image Input', level=1) 66 | image_stream = io.BytesIO() 67 | image_input.save(image_stream, format='PNG') 68 | image_stream.seek(0) 69 | doc.add_picture(image_stream, width=Inches(4)) # Adjust the width as needed 70 | 71 | return doc 72 | 73 | st.set_page_config(layout="wide") 74 | 75 | def main(): 76 | st.title("Article Generator App using Llama 2") 77 | 78 | user_input = st.text_input("Please enter the idea/topic for the article you want to generate!") 79 | 80 | image_input = st.text_input("Please enter the topic for the image you want to fetch!") 81 | 82 | if len(user_input) > 0 and len(image_input) > 0: 83 | 84 | col1, col2, col3 = st.columns([1,2,1]) 85 | 86 | with col1: 87 | st.subheader("Generated Content by Llama 2") 88 | st.write("Topic of the article is: " + user_input) 89 | st.write("Image of the article is: " + image_input) 90 | prompt_template = """You are a digital marketing and SEO expert and your task is to write article so write an article on the given topic: {user_input}. The article must be under 800 words. The article should be be lengthy. 91 | """ 92 | llm_call = load_llm(max_tokens=800, prompt_template=prompt_template) 93 | print(llm_call) 94 | result = llm_call(user_input) 95 | if len(result) > 0: 96 | st.info("Your article has been been generated successfully!") 97 | st.write(result) 98 | else: 99 | st.error("Your article couldn't be generated!") 100 | 101 | with col2: 102 | st.subheader("Fetched Image") 103 | image_url = get_src_original_url(image_input) 104 | st.image(image_url) 105 | 106 | with col3: 107 | st.subheader("Final Article to Download") 108 | image_input = "temp_image.jpg" 109 | doc = create_word_docx(user_input, result['text'], Image.open(image_input)) 110 | 111 | # Save the Word document to a BytesIO buffer 112 | doc_buffer = io.BytesIO() 113 | doc.save(doc_buffer) 114 | doc_buffer.seek(0) 115 | 116 | # Prepare the download link 117 | st.download_button( 118 | label='Download Word Document', 119 | data=doc_buffer, 120 | file_name='document.docx', 121 | mime='application/vnd.openxmlformats-officedocument.wordprocessingml.document' 122 | ) 123 | 124 | 125 | if __name__ == "__main__": 126 | main() 127 | 128 | -------------------------------------------------------------------------------- /fetch_image.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | def fetch_photo(query): 4 | api_key = 'YOUR_API_KEY' 5 | 6 | url = 'https://api.pexels.com/v1/search' 7 | headers = { 8 | 'Authorization': api_key, 9 | } 10 | 11 | params = { 12 | 'query': query, 13 | 'per_page': 1, 14 | } 15 | 16 | response = requests.get(url, headers=headers, params=params) 17 | 18 | # Check if the request was successful (status code 200) 19 | if response.status_code == 200: 20 | data = response.json() 21 | photos = data.get('photos', []) 22 | if photos: 23 | src_original_url = photos[0]['src']['original'] 24 | return src_original_url 25 | else: 26 | print("No photos found for the given query.") 27 | else: 28 | print(f"Error: {response.status_code}, {response.text}") 29 | 30 | return None 31 | 32 | # Example usage of the function 33 | query = 'AI' 34 | src_original_url = fetch_photo(query) 35 | if src_original_url: 36 | print(f"Original URL for query '{query}': {src_original_url}") 37 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /sample.txt: -------------------------------------------------------------------------------- 1 | {'user_input': 'Sustainability', 'text': ' Title: The Importance of Sustainability in Digital Marketing\n\nSustainability has become an integral part of our daily lives, including our digital marketing strategies. As a digital marketer, it is crucial to understand the importance of sustainability and how it can positively impact your business. In this article, we will explore the reasons why sustainability matters in digital marketing and how you can incorporate it into your strategies .\nFirstly, sustainability in digital marketing means reducing the environmental impact of our online activities. This includes reducing energy consumption, minimizing paper waste, and promoting eco-friendly practices. By adopting sustainable digital marketing practices, businesses can significantly reduce their carbon footprint and contribute to a greener future.\nSecondly, sustainability is essential for building trust and credibility with customers. Consumers are increasingly conscious of the environmental impact of their purchases and want to support brands that share their values. By incorporating sustainable practices into your digital marketing strategies, you can demonstrate your commitment to ethical business practices and appeal to environmentally-conscious consumers.\nLastly, sustainability can'} 2 | --------------------------------------------------------------------------------