Ragulvasanth66 commited on
Commit
0614efa
·
verified ·
1 Parent(s): ae6595e
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -6,6 +6,8 @@ import pandas as pd
6
  from huggingface_hub import InferenceClient
7
  from dotenv import load_dotenv
8
  import json
 
 
9
 
10
  load_dotenv()
11
 
@@ -13,6 +15,8 @@ load_dotenv()
13
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
14
 
15
  # --- Basic Agent Definition ---
 
 
16
  class BasicAgent:
17
  def __init__(self):
18
  self.token = os.getenv("token")
@@ -22,11 +26,16 @@ class BasicAgent:
22
  def __call__(self, question: str) -> str:
23
  prompt = f"Answer this question concisely and clearly. Only return the final answer.\nQuestion: {question}"
24
  try:
25
- response = self.client.text_generation(prompt, max_new_tokens=100)
26
- return response.strip()
 
 
 
27
  except Exception as e:
28
- print(f"Error calling inference API: {e}")
29
- return f"error: {e} | token used: {self.token}"
 
 
30
 
31
 
32
  def run_and_submit_all(profile: gr.OAuthProfile | None):
 
6
  from huggingface_hub import InferenceClient
7
  from dotenv import load_dotenv
8
  import json
9
+ from huggingface_hub import InferenceClient
10
+ import traceback
11
 
12
  load_dotenv()
13
 
 
15
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
16
 
17
  # --- Basic Agent Definition ---
18
+
19
+
20
  class BasicAgent:
21
  def __init__(self):
22
  self.token = os.getenv("token")
 
26
  def __call__(self, question: str) -> str:
27
  prompt = f"Answer this question concisely and clearly. Only return the final answer.\nQuestion: {question}"
28
  try:
29
+ response = self.client.conversational(
30
+ messages=[{"role": "user", "content": prompt}]
31
+ )
32
+ print("✅ Raw response:", response)
33
+ return response[0]["generated_text"].strip()
34
  except Exception as e:
35
+ print("Error calling inference API")
36
+ traceback.print_exc()
37
+ return f"error: {str(e)}"
38
+
39
 
40
 
41
  def run_and_submit_all(profile: gr.OAuthProfile | None):