Rename app.py to app.pyx
Browse files- app.py → app.pyx +18 -16
app.py → app.pyx
RENAMED
|
@@ -1,25 +1,26 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def kelvin_to_celsius(temp_kelvin):
|
| 5 |
return temp_kelvin - 273.15
|
| 6 |
|
| 7 |
def get_weather(city_name, api_key):
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
main_data = data.get("main", {})
|
| 15 |
-
weather_data = data.get("weather", [{}])[0]
|
| 16 |
-
temperature = kelvin_to_celsius(main_data.get("temp", 0))
|
| 17 |
-
pressure = main_data.get("pressure", "N/A")
|
| 18 |
-
humidity = main_data.get("humidity", "N/A")
|
| 19 |
-
weather_description = weather_data.get("description", "N/A")
|
| 20 |
-
return temperature, pressure, humidity, weather_description
|
| 21 |
-
else:
|
| 22 |
-
return None
|
| 23 |
|
| 24 |
def compare_weather(city1, city2):
|
| 25 |
api_key = "91b23cab82ee530b2052c8757e343b0d"
|
|
@@ -40,7 +41,8 @@ def compare_weather(city1, city2):
|
|
| 40 |
Humidity: {weather2[2]}%
|
| 41 |
Condition: {weather2[3]}
|
| 42 |
"""
|
| 43 |
-
|
|
|
|
| 44 |
else:
|
| 45 |
return "Error fetching weather data for one or both cities."
|
| 46 |
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
+
import openai
|
| 5 |
+
|
| 6 |
+
# Get OpenAI API key from environment variable
|
| 7 |
+
openai_api_key = os.environ.get("OPENAI_API_KEY")
|
| 8 |
+
if not openai_api_key:
|
| 9 |
+
raise ValueError("OpenAI API key not found!")
|
| 10 |
+
|
| 11 |
+
# Authenticate with OpenAI using your API key
|
| 12 |
+
openai.api_key = openai_api_key
|
| 13 |
|
| 14 |
def kelvin_to_celsius(temp_kelvin):
|
| 15 |
return temp_kelvin - 273.15
|
| 16 |
|
| 17 |
def get_weather(city_name, api_key):
|
| 18 |
+
# ... [same as your previous code] ...
|
| 19 |
+
|
| 20 |
+
def summarize_text(text):
|
| 21 |
+
"""Summarize the provided text using OpenAI."""
|
| 22 |
+
response = openai.Completion.create(engine="davinci", prompt=f"Summarize the following weather comparison:\n\n{text}", max_tokens=150)
|
| 23 |
+
return response.choices[0].text.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
def compare_weather(city1, city2):
|
| 26 |
api_key = "91b23cab82ee530b2052c8757e343b0d"
|
|
|
|
| 41 |
Humidity: {weather2[2]}%
|
| 42 |
Condition: {weather2[3]}
|
| 43 |
"""
|
| 44 |
+
summary = summarize_text(comparison)
|
| 45 |
+
return summary
|
| 46 |
else:
|
| 47 |
return "Error fetching weather data for one or both cities."
|
| 48 |
|