Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,13 +9,14 @@ def preprocess_city_name_and_generate_insight(city_name):
|
|
| 9 |
return city_name, "Hugging Face token is not set in the environment variables."
|
| 10 |
|
| 11 |
try:
|
| 12 |
-
|
| 13 |
-
|
|
|
|
| 14 |
prompt = f"Generate a short, interesting fact about {city_name} in less than 10 words."
|
| 15 |
-
|
| 16 |
-
result = client
|
| 17 |
-
|
| 18 |
-
insight = result[
|
| 19 |
except Exception as e:
|
| 20 |
print(f"Error generating insight: {str(e)}")
|
| 21 |
insight = "Could not generate insight due to an error."
|
|
@@ -23,7 +24,6 @@ def preprocess_city_name_and_generate_insight(city_name):
|
|
| 23 |
return city_name, insight
|
| 24 |
|
| 25 |
|
| 26 |
-
|
| 27 |
def get_weather(city_name):
|
| 28 |
corrected_city_name, city_insight = preprocess_city_name_and_generate_insight(city_name)
|
| 29 |
API_Key = os.getenv("OPENWEATHER_API_KEY")
|
|
|
|
| 9 |
return city_name, "Hugging Face token is not set in the environment variables."
|
| 10 |
|
| 11 |
try:
|
| 12 |
+
|
| 13 |
+
client = InferenceClient(token=token)
|
| 14 |
+
|
| 15 |
prompt = f"Generate a short, interesting fact about {city_name} in less than 10 words."
|
| 16 |
+
|
| 17 |
+
result = client(inputs=prompt, model_id="gpt2")
|
| 18 |
+
|
| 19 |
+
insight = result['generated_text'].strip() if 'generated_text' in result else "No insight generated."
|
| 20 |
except Exception as e:
|
| 21 |
print(f"Error generating insight: {str(e)}")
|
| 22 |
insight = "Could not generate insight due to an error."
|
|
|
|
| 24 |
return city_name, insight
|
| 25 |
|
| 26 |
|
|
|
|
| 27 |
def get_weather(city_name):
|
| 28 |
corrected_city_name, city_insight = preprocess_city_name_and_generate_insight(city_name)
|
| 29 |
API_Key = os.getenv("OPENWEATHER_API_KEY")
|