From c75d067f41897f50971641ab7f940412d8819624 Mon Sep 17 00:00:00 2001 From: Artin | Projects Date: Thu, 26 Dec 2024 16:09:20 +0330 Subject: [PATCH] Weather App by GPT-4 Weather app by the last language model of ChatGPT (GPT-4). Purpose: Showing the evolution of "Natural Language Processing" (NLP) in the new world of A.I. --- WeatherApp.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 WeatherApp.py diff --git a/WeatherApp.py b/WeatherApp.py new file mode 100644 index 0000000..9ea618e --- /dev/null +++ b/WeatherApp.py @@ -0,0 +1,37 @@ +import tkinter as tk +import requests + +def get_weather(): + city = city_entry.get() + api_key = "YOUR_API_KEY" # جایگزین با کلید API خود + url = f'http://api.weatherapi.com/v1/current.json?key={WEATHER_KEY}&q={weather}&aqi=no' + response = requests.get(url) + data = response.json() + + if response.status_code == 200: + weather = f"City: {data['name']}\nTemperature: {data['main']['temp']}°C\nWeather: {data['weather'][0]['description']}" + result_label.config(text=weather) + else: + result_label.config(text="City not found!") + +# ایجاد پنجره اصلی +root = tk.Tk() +root.title("Weather App") + +# ورودی شهر +city_label = tk.Label(root, text="Enter City:") +city_label.pack(pady=5) + +city_entry = tk.Entry(root) +city_entry.pack(pady=5) + +# دکمه برای دریافت آب و هوا +get_weather_button = tk.Button(root, text="Get Weather", command=get_weather) +get_weather_button.pack(pady=10) + +# نمایش نتیجه +result_label = tk.Label(root, text="") +result_label.pack(pady=20) + +# اجرای حلقه اصلی +root.mainloop()