WingNeville commited on
Commit
e0c1798
·
verified ·
1 Parent(s): 97c86f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -15,7 +15,7 @@ def test_api_connection(query: str, api_key: str) -> str:
15
  # Return the classification result or confirmation of success
16
  return f"API connection successful! Response: {response}"
17
  except Exception as e:
18
- return f"Error: Failed to connect to Hugging Face API. Check your API key or network. Details: {str(e)}"
19
 
20
  ################################ Simple agent class #######################################
21
  class MyFirstAgent:
@@ -33,6 +33,8 @@ class MyFirstAgent:
33
 
34
  # Route to the API test tool
35
  try:
 
 
36
  return self.tools["test_api"](query, api_key)
37
  except:
38
  return "Error: Failed to process the query. Ensure the query and API key are valid."
@@ -43,9 +45,9 @@ agent = MyFirstAgent()
43
  #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Define Gradio interface function #############################
44
  def run_agent(query):
45
  # Retrieve API key from environment variable
46
- api_key = os.getenv("ReadOnly")
47
  if not api_key:
48
- return "Error: ReadOnly not found in environment variables."
49
  return agent.run(query, api_key)
50
 
51
  #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Create and launch Gradio interface #########################################
@@ -54,7 +56,7 @@ interface = gr.Interface(
54
  inputs=gr.Textbox(label="Enter a test query", placeholder="e.g., This is a test sentence"),
55
  outputs=gr.Textbox(label="API Test Response"),
56
  title="My First Agent - Hugging Face API Test",
57
- description="Enter a test query to verify the Hugging Face API connection using the wingTokenRead secret."
58
  )
59
 
60
  if __name__ == "__main__":
 
15
  # Return the classification result or confirmation of success
16
  return f"API connection successful! Response: {response}"
17
  except Exception as e:
18
+ return f"Error: Failed to connect to Hugging Face API. Details: {str(e)}\n\nDebugging steps:\n1. Verify 'wingTokenRead' in Spaces Settings > Repository secrets matches the token from https://huggingface.co/settings/tokens.\n2. Ensure the token has read permissions and is not expired.\n3. Rebuild the Space to apply changes.\n4. If the issue persists, try a new token with read/write permissions."
19
 
20
  ################################ Simple agent class #######################################
21
  class MyFirstAgent:
 
33
 
34
  # Route to the API test tool
35
  try:
36
+ if not query:
37
+ return "Error: Please provide a non-empty query."
38
  return self.tools["test_api"](query, api_key)
39
  except:
40
  return "Error: Failed to process the query. Ensure the query and API key are valid."
 
45
  #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Define Gradio interface function #############################
46
  def run_agent(query):
47
  # Retrieve API key from environment variable
48
+ api_key = os.getenv("wingTokenRead")
49
  if not api_key:
50
+ return "Error: wingTokenRead not found in environment variables. Please set it in Spaces Settings > Repository secrets at https://huggingface.co/spaces."
51
  return agent.run(query, api_key)
52
 
53
  #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Create and launch Gradio interface #########################################
 
56
  inputs=gr.Textbox(label="Enter a test query", placeholder="e.g., This is a test sentence"),
57
  outputs=gr.Textbox(label="API Test Response"),
58
  title="My First Agent - Hugging Face API Test",
59
+ description="Enter a test query to verify the Hugging Face API connection using the wingTokenRead secret. Created on May 29, 2025, 11:42 PM HKT."
60
  )
61
 
62
  if __name__ == "__main__":