NeuroAbundance commited on
Commit
d2b2cbf
·
1 Parent(s): b000d83

Unsuccessful attempts

Browse files
Files changed (3) hide show
  1. .gitignore +2 -0
  2. app.py +24 -5
  3. requirements.txt +2 -1
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ venv
2
+ .env
app.py CHANGED
@@ -10,14 +10,33 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
  # --- Basic Agent Definition ---
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
 
 
 
13
  class BasicAgent:
14
  def __init__(self):
15
  print("BasicAgent initialized.")
 
 
 
 
 
 
 
 
 
 
 
16
  def __call__(self, question: str) -> str:
17
  print(f"Agent received question (first 50 chars): {question[:50]}...")
18
- fixed_answer = "This is a default answer."
19
- print(f"Agent returning fixed answer: {fixed_answer}")
20
- return fixed_answer
 
 
 
 
 
21
 
22
  def run_and_submit_all( profile: gr.OAuthProfile | None):
23
  """
@@ -91,7 +110,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
91
  print("Agent did not produce any answers to submit.")
92
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
93
 
94
- # 4. Prepare Submission
95
  submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
96
  status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
97
  print(status_update)
@@ -193,4 +212,4 @@ if __name__ == "__main__":
193
  print("-"*(60 + len(" App Starting ")) + "\n")
194
 
195
  print("Launching Gradio Interface for Basic Agent Evaluation...")
196
- demo.launch(debug=True, share=False)
 
10
 
11
  # --- Basic Agent Definition ---
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
+ import os
14
+ from llama_index import LLMPredictor, ServiceContext
15
+
16
  class BasicAgent:
17
  def __init__(self):
18
  print("BasicAgent initialized.")
19
+ if not os.getenv("HF_TOKEN"):
20
+ raise ValueError("HF_TOKEN environment variable not set. Please set HF_TOKEN with your Hugging Face API token.")
21
+
22
+ # Initialize LLMPredictor with HuggingFace model
23
+ self.llm_predictor = LLMPredictor(
24
+ model_type="LLM", # Using HuggingFace model type
25
+ model_id="llama-7b", # Model ID from HuggingFace
26
+ max_length=100 # Default max length for generation
27
+ )
28
+ self.service_context = ServiceContext.from_defaults(llm_predictor=self.llm_predictor)
29
+
30
  def __call__(self, question: str) -> str:
31
  print(f"Agent received question (first 50 chars): {question[:50]}...")
32
+ # Use the service context to generate answer
33
+ response = self.service_context.llm_predictor.predict(
34
+ prompt=question,
35
+ max_length=100
36
+ )
37
+ answer = response.text # Extract text from response object
38
+ print(f"Agent returning answer: {answer}")
39
+ return answer
40
 
41
  def run_and_submit_all( profile: gr.OAuthProfile | None):
42
  """
 
110
  print("Agent did not produce any answers to submit.")
111
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
112
 
113
+ # 4. Prepare Submission
114
  submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
115
  status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
116
  print(status_update)
 
212
  print("-"*(60 + len(" App Starting ")) + "\n")
213
 
214
  print("Launching Gradio Interface for Basic Agent Evaluation...")
215
+ demo.launch(debug=True, share=False)
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  gradio
2
- requests
 
 
1
  gradio
2
+ requests
3
+ llama-index