ArceusInception commited on
Commit
3865fc3
·
verified ·
1 Parent(s): 9fc5504

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -1,18 +1,19 @@
1
  import gradio as gr
2
  import requests
3
  import os
4
- from huggingface_hub import InferenceClient
5
 
6
  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
 
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)}")
 
1
  import gradio as gr
2
  import requests
3
  import os
4
+ from huggingface_hub import InferenceApi # Correct import for inference
5
 
6
  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
 
11
+ # Using the InferenceApi class correctly
12
+ client = InferenceApi("gpt2", token)
13
  prompt = f"Generate a short, interesting fact about {city_name} in less than 10 words:"
14
 
15
  try:
16
+ result = client(predict=prompt) # Using predict or the correct method
17
  insight = result[0]['generated_text'].strip() if result else "No insight generated."
18
  except Exception as e:
19
  print(f"Error generating insight: {str(e)}")