ArceusInception commited on
Commit
9fc5504
·
verified ·
1 Parent(s): 8af5b38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -7,16 +7,20 @@ def preprocess_city_name_and_generate_insight(city_name):
7
  token = os.getenv("HF_TOKEN")
8
  if not token:
9
  return city_name, "Hugging Face token is not set in the environment variables."
 
10
  client = InferenceClient(model="gpt2", token=token)
11
  prompt = f"Generate a short, interesting fact about {city_name} in less than 10 words:"
 
12
  try:
13
- result = client.call(inputs=prompt) # Correct method to make an inference call
14
- # Assuming the GPT-2 model completes the sentence in a meaningful way
15
- insight = result[0]['generated_text'].strip()
16
  except Exception as e:
 
17
  insight = "Could not generate insight due to an error."
 
18
  return city_name, insight
19
 
 
20
  def get_weather(city_name):
21
  corrected_city_name, city_insight = preprocess_city_name_and_generate_insight(city_name)
22
  API_Key = os.getenv("OPENWEATHER_API_KEY")
 
7
  token = os.getenv("HF_TOKEN")
8
  if not token:
9
  return city_name, "Hugging Face token is not set in the environment variables."
10
+
11
  client = InferenceClient(model="gpt2", token=token)
12
  prompt = f"Generate a short, interesting fact about {city_name} in less than 10 words:"
13
+
14
  try:
15
+ result = client.call(inputs=prompt)
16
+ insight = result[0]['generated_text'].strip() if result else "No insight generated."
 
17
  except Exception as e:
18
+ print(f"Error generating insight: {str(e)}")
19
  insight = "Could not generate insight due to an error."
20
+
21
  return city_name, insight
22
 
23
+
24
  def get_weather(city_name):
25
  corrected_city_name, city_insight = preprocess_city_name_and_generate_insight(city_name)
26
  API_Key = os.getenv("OPENWEATHER_API_KEY")