Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
6
-
7
  # (Keep Constants as is)
8
  # --- Constants ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
@@ -12,12 +12,20 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
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
  """
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
7
  # (Keep Constants as is)
8
  # --- Constants ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
  class BasicAgent:
14
  def __init__(self):
15
+ # Initialize the tokenizer and model for CodeT5
16
+ print("Loading CodeT5+ model...")
17
+ self.tokenizer = AutoTokenizer.from_pretrained("Salesforce/codet5p-770m")
18
+ self.model = AutoModelForSeq2SeqLM.from_pretrained("Salesforce/codet5p-770m")
19
+ print("BasicAgent initialized with CodeT5+ model.")
20
+
21
  def __call__(self, question: str) -> str:
22
+ # Process the question and generate an answer using CodeT5
23
+ print(f"Agent received question: {question[:50]}...")
24
+ inputs = self.tokenizer(question, return_tensors="pt", truncation=True, padding=True)
25
+ outputs = self.model.generate(**inputs, max_new_tokens=128)
26
+ answer = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
27
+ print(f"Agent returning answer: {answer[:50]}...")
28
+ return answer
29
 
30
  def run_and_submit_all( profile: gr.OAuthProfile | None):
31
  """