Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Build a Text Summarization app using Reflex (Pure Python)

Posted on Oct 19 Reflex is an open-source, full-stack Python framework that makes it easy to build and deploy web apps in minutes. You have most of the features of a frontend library like Reactjs and a backend framework like Django in one with ease in development and deployment. All while developing in a single language PYTHON.We will use Reflex to build a text summarization app where a user will be able to input a text and the Openai llm and langchain will generate a summary of the text.The following will be the output of the app:First, get your own OpenAI API key:Create a new folder and name it text_summarizer then open it with a Code editor like VS Code.Open the terminal. Use the following command to create a virtual environment .venv and activate it:We will need to install reflex to build the app and also openai tiktoken chromadb langchain to generate the text summariesRun the following command in the terminal:Now, we need to create the project using reflex. Run the following command to initialize the template app in text_summarizer directory.The above command will create the following file structure in text_summarizer directory:You can run the app using the following command in your terminal to see a welcome page when you go to http://localhost:3000/ in your browserWe need to build the structure and interface of the app and add components. Go to the text_summarizer subdirectory and open the text_summarizer.py file. This is where we will add components to build the structure and interface of the app. Add the following code to it:The above code will render a text and the text area input, password input to enter your openai key, a submit button, and a box to show the summaryCreate a new file state.py in the text_summarizer subdirectory and add the following code:The above code uses load_summarize_chain with chain_type of "stuff" to generate the summary and send it to the front end. When the user clicks the "Summarize text" button, it triggers and calls the start_process method. start_process method assigns the is_loading argument of "Summarize text" button to True so that the button can start spinning with the text "generating summary...." to show that the app is generating the summary. start_process method then calls summarize method to generate the summary with the help of openai llm "gpt-3.5-turbo-16k" and yield the result or summary to the frontend. It then changes the is_loading argument of the button to False and loading_text to an empty string so as to return the button to its initial state.Create a new file style.py in the text_summarizer subdirectory and add the following code. This will add styling to the page and components:You can add the .venv directory to the .gitignore file to get the following:Run the following in the terminal to start the app:You should see an interface as follows when you go to http://localhost:3000/ You can input the text that you want to be summarized. Also, enter your openai API key and then click the button to get your summarized text.Reflex is awesome and a game-changer. You should try it out. You can get the code: https://github.com/emmakodes/text_summarizer.gitTemplates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse Anand Das - Sep 21 Mike Young - Sep 22 Victoria Drake - Sep 19 Pavan Belagatti - Sep 15 Once suspended, emmakodes_ will not be able to comment or publish posts until their suspension is removed. Once unsuspended, emmakodes_ will be able to comment and publish posts again. Once unpublished, all posts by emmakodes_ will become hidden and only accessible to themselves. If emmakodes_ is not suspended, they can still re-publish their posts from their dashboard. Note: Once unpublished, this post will become invisible to the public and only accessible to Emmanuel Onwuegbusi. They can still re-publish the post if they are not suspended. Thanks for keeping DEV Community safe. Here is what you can do to flag emmakodes_: emmakodes_ consistently posts content that violates DEV Community's code of conduct because it is harassing, offensive or spammy. Unflagging emmakodes_ will restore default visibility to their posts. DEV Community — A constructive and inclusive social network for software developers. With you every step of your journey. Built on Forem — the open source software that powers DEV and other inclusive communities.Made with love and Ruby on Rails. DEV Community © 2016 - 2023. We're a place where coders share, stay up-to-date and grow their careers.



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

Build a Text Summarization app using Reflex (Pure Python)

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×