Build your first Python app in 5 minutes: ‘Ask Me Anything’

Before jumping into the Python app, let us have a brief about Python. We all know that Python is a general-purpose programming language which means Python can be used for various requirements whether it is data science, machine learning, task automation, game development, or web-based app development. Python has a wide range of libraries to perform tasks like numpy for calculations, pandas for data analytics, and seaborn for data visualizations, in the same way, python has a library called Streamlit which helps us to create web-based applications.

In this blog, we are creating a simple Ask Me Anything application, where any user can input the name of the topic and search for it. In this program, we will use libraries like Streamlit and Wikipedia.

Step 1: In the first step of the Python app, we need to install Streamlit and Wikipedia libraries.

We will give command in the terminal and then press enter and wait for a few seconds and then we will give the command for installation of the Wikipedia library

Press enter and wait for a few seconds.

For more such content and regular updates, follow us on FacebookInstagramLinkedIn

Step 2: Now we are going to import these libraries.Python app

import streamlit as st
import wikipedia
Python

Step 3: In this step, we are going to create a title for the Python app and an input box where a user can search for the topic.

st.title('Welcome to, "Ask me Anything"')
topic=st.text_input('Enter the topic you want to search here')
Python

topic is a variable that stores the topic which will be inputted by the user.

Output:

Step 4: Now we need to create a button “Generate” which will generate texts about the topic searched by the user.Python app

if st.button('Generate'):
    text=wikipedia.summary(topic,sentences=10)
    text=text.split('.')
    st.subheader(f'You have searched for, {topic.title()}')
    for i,t in enumerate(text):
        st.write(f'{i+1}. {t}')
Python
  • In this step, we have created and applied the if condition which checks if the button is clicked.
  • Now text is a variable that stores the generated by the summary function of the Wikipedia library with arguments topic and sentences=10 (to generate 10 lines of the topic).
  • Now the summary will be in a paragraph(string data type) therefore we will use the split method and ‘.’ as a separator to break the paragraph into lines(list data type).
  • Now we will use the subheader function to print a simple message “You have searched for (topic given by user).”
  • Next, we will use the for loop that will use the enumerate function on the text variable with 2 variables
  • At last, we will print the generated into pointers.

Step 5: Finally, it is time for the results.Python app

python app

Python is the easiest and most general-purpose programming language which means it can be used to perform a variety of tasks whether web-based development, software development, data analysis, and a lot more. This program is just an example of the easiness of Python programming language. You can create more such Python app with the help of Streamlit and other libraries. Python python app

Right now, data science has become one of the fields where companies are hiring regularly and there is a lot of gap in the demand and supply of data analysts in the market.

If you wish to learn more about data science or want to curve your career in the data science field feel free to join our free workshop on Masters in Data Science with PowerBI, where you will get to know how exactly the data science field works and why companies are ready to pay handsome salaries in this field.

In this workshop, you will get to know each tool and technology from scratch that will make you skillfully eligible for any data science profile.

To join this workshop, register yourself on consoleflare and we will call you back.

Thinking, Why Console Flare?

  • Recently, ConsoleFlare has been recognized as one of the Top 10 Most Promising Data Science Training Institutes of 2023.
  • Console Flare offers the opportunity to learn Data Science in Hindi, just like how you speak daily.
  • Console Flare believes in the idea of “What to learn and what not to learn” and this can be seen in their curriculum structure. They have designed their program based on what you need to learn for data science and nothing else.
  • Want more reasons,

Register yourself on consoleflare and we will call you back.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top