Skip to content

udityamerit/Weather-Forecasting-Web-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

Streamlit is an open-source app framework for Machine Learning and Data Science projects. It's a powerful tool to create web applications with minimal code. In this guide, we will build a weather forecasting web app using Streamlit and a weather API to fetch data.

Prerequisites

  • Basic understanding of Python
  • Knowledge of using APIs
  • Streamlit library installed (pip install streamlit)
  • Access to a weather API (like OpenWeatherMap or Weatherstack)

Key Weather Forecasting Terms

  1. Temperature: The degree of hotness or coldness measured on a definite scale.
  2. Humidity: The amount of water vapor in the air.
  3. Wind Speed: The speed at which the wind is blowing.
  4. Pressure: The force exerted by the atmosphere at a given point.
  5. Precipitation: Any form of water - liquid or solid - falling from the sky, including rain, snow, sleet, and hail.
  6. Visibility: The distance one can see as determined by light and weather conditions.
  7. Weather Condition: Describes the state of the atmosphere, such as clear, cloudy, rainy, or snowy.

Steps to Create the Weather Forecasting Web App

1. Set Up Your Environment

First, install Streamlit and requests libraries using pip:

pip install streamlit requests

2. Import Necessary Libraries

import streamlit as st
import requests

3. Create the Main Function

your logic

4. Run the App

Save the script as weather_app.py and run it using Streamlit:

streamlit run weather_app.py

Explanation of Code

  1. Setting Up: Import Streamlit and requests libraries.
  2. Main Function: main() handles the app's main logic, displaying the title, text input for city name, and a button to fetch weather data.
  3. API Call: get_weather() function makes a GET request to the weather API with the provided city name and API key. It returns the weather data in JSON format if the request is successful.
  4. Displaying Data: display_weather() function takes the JSON response and extracts relevant information (temperature, humidity, etc.), displaying it in a readable format using Streamlit.

Conclusion

By following these steps, you will have a functional weather forecasting web app using Streamlit. This app can be further enhanced by adding features like a 5-day forecast, charts for visualizing weather data, and user authentication for personalizing the experience.

Releases

No releases published

Packages

No packages published

Languages