Spaces:
Runtime error
Runtime error
Commit
·
1eab79c
1
Parent(s):
dc60bd7
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,55 +1,36 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import openai
|
| 3 |
import requests
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
response
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
return
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
iface = gr.Interface(
|
| 37 |
-
fn=get_weather_data,
|
| 38 |
-
inputs="text",
|
| 39 |
-
outputs="text",
|
| 40 |
-
title="Weather Forecast",
|
| 41 |
-
description="Enter the name of a city to get the weather forecast.",
|
| 42 |
-
examples=[["New York"], ["London"], ["Tokyo"]]
|
| 43 |
-
)
|
| 44 |
-
|
| 45 |
-
feedback_iface = gr.Interface(
|
| 46 |
-
fn=get_weather_feedback,
|
| 47 |
-
inputs="text",
|
| 48 |
-
outputs="text",
|
| 49 |
-
title="Feedback",
|
| 50 |
-
description="Enter a weather description to get feedback.",
|
| 51 |
-
examples=[["sunny"], ["rainy"], ["cloudy"]]
|
| 52 |
-
)
|
| 53 |
|
| 54 |
if __name__ == "__main__":
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
| 1 |
import requests
|
| 2 |
+
|
| 3 |
+
def get_weather_data(api_key, city):
|
| 4 |
+
base_url = "http://api.openweathermap.org/data/2.5/weather"
|
| 5 |
+
params = {"q": city, "appid": api_key, "units": "metric"}
|
| 6 |
+
|
| 7 |
+
response = requests.get(base_url, params=params)
|
| 8 |
+
|
| 9 |
+
if response.status_code == 200:
|
| 10 |
+
return response.json()
|
| 11 |
+
else:
|
| 12 |
+
print("Failed to fetch weather data.")
|
| 13 |
+
return None
|
| 14 |
+
|
| 15 |
+
def display_weather_info(weather_data):
|
| 16 |
+
if weather_data:
|
| 17 |
+
city = weather_data["name"]
|
| 18 |
+
weather = weather_data["weather"][0]["description"]
|
| 19 |
+
temperature = weather_data["main"]["temp"]
|
| 20 |
+
wind_speed = weather_data["wind"]["speed"]
|
| 21 |
+
|
| 22 |
+
print(f"Weather in {city}: {weather}")
|
| 23 |
+
print(f"Temperature: {temperature}°C")
|
| 24 |
+
print(f"Wind Speed: {wind_speed} m/s")
|
| 25 |
+
else:
|
| 26 |
+
print("Weather data is unavailable.")
|
| 27 |
+
|
| 28 |
+
def main():
|
| 29 |
+
api_key = "1aafc3163909c1493596da9340e00aee" # Replace with your OpenWeatherMap API key
|
| 30 |
+
city = input("Enter a city name: ")
|
| 31 |
+
|
| 32 |
+
weather_data = get_weather_data(api_key, city)
|
| 33 |
+
display_weather_info(weather_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
if __name__ == "__main__":
|
| 36 |
+
main()
|