ArceusInception commited on
Commit
16ce4ec
·
verified ·
1 Parent(s): 156235b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
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
- client = InferenceClient(model_id="gpt2", api_token=token)
13
- # Construct the prompt for GPT-2
 
14
  prompt = f"Generate a short, interesting fact about {city_name} in less than 10 words."
15
- # Make the prediction request
16
- result = client.predict(inputs=prompt)
17
- # Process the result
18
- insight = result[0]['generated_text'].strip() if result else "No insight generated."
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")