Spaces:
Sleeping
Sleeping
test code changes (#2)
Browse files- test code changes (bb33938925eddfa781bdd22a88f54c39523444a1)
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
"""
|