Visionkambanje commited on
Commit
2e84b5d
·
verified ·
1 Parent(s): d9fd11b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -9,11 +9,13 @@ from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel, Py
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
  # --- Hugging Face API Key ---
12
- HF_API_KEY = os.environ["HF_TOKEN"]
 
 
13
 
14
  # --- Initialize Hugging Face Model ---
15
  model = InferenceClientModel(
16
- model_id="google/embeddinggemma-300m", # example HF chat model
17
  token=HF_API_KEY
18
  )
19
 
@@ -30,15 +32,19 @@ class BasicAgent:
30
  ],
31
  model=self.model
32
  )
33
- print("BasicAgent initialized with Hugging Face model.")
34
 
35
  def __call__(self, question: str) -> str:
36
  print(f"Agent received question (first 50 chars): {question[:50]}...")
37
  try:
38
  answer = self.agent.run(question)
 
 
 
39
  except Exception as e:
40
- answer = f"AGENT ERROR: {e}"
41
- return answer
 
42
 
43
  # --- Run & Submit Function ---
44
  def run_and_submit_all(profile: gr.OAuthProfile | None = None):
 
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
  # --- Hugging Face API Key ---
12
+ HF_API_KEY = os.environ.get("HF_API_KEY")
13
+ if not HF_API_KEY:
14
+ raise ValueError("❌ Hugging Face API key not found. Please add it under Settings → Variables and secrets.")
15
 
16
  # --- Initialize Hugging Face Model ---
17
  model = InferenceClientModel(
18
+ model_id="HuggingFaceH4/zephyr-7b-beta", # chat model
19
  token=HF_API_KEY
20
  )
21
 
 
32
  ],
33
  model=self.model
34
  )
35
+ print("BasicAgent initialized with Hugging Face model.")
36
 
37
  def __call__(self, question: str) -> str:
38
  print(f"Agent received question (first 50 chars): {question[:50]}...")
39
  try:
40
  answer = self.agent.run(question)
41
+ if not answer:
42
+ return "⚠️ Model returned no answer."
43
+ return answer
44
  except Exception as e:
45
+ print(f" Error during agent run: {e}")
46
+ return f"AGENT ERROR: {str(e)}"
47
+
48
 
49
  # --- Run & Submit Function ---
50
  def run_and_submit_all(profile: gr.OAuthProfile | None = None):