Spaces:
Sleeping
Sleeping
Qscar KIM commited on
Commit ยท
604f0fd
1
Parent(s): d322966
update codes
Browse files
app.py
CHANGED
|
@@ -5,7 +5,8 @@ import inspect
|
|
| 5 |
import pandas as pd
|
| 6 |
import time
|
| 7 |
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
# --- Constants ---
|
| 11 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
@@ -14,27 +15,36 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 14 |
# ----- THIS IS WHERE YOU CAN BUILD WHAT YOU WANT ------
|
| 15 |
class BasicAgent:
|
| 16 |
def __init__(self):
|
| 17 |
-
# Hugging Face ํ๊ฒฝ์
|
| 18 |
-
self.
|
| 19 |
-
|
| 20 |
-
|
| 21 |
)
|
| 22 |
-
print("BasicAgent initialized.")
|
| 23 |
|
| 24 |
def __call__(self, question: str) -> str:
|
| 25 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 26 |
|
| 27 |
try:
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
print(f"Agent returning answer: {final_answer}")
|
| 34 |
return final_answer
|
| 35 |
|
| 36 |
except Exception as e:
|
| 37 |
-
print(f"Error running model: {e}")
|
| 38 |
return "unknown"
|
| 39 |
|
| 40 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
import time
|
| 7 |
|
| 8 |
+
# smolagents์ ๋ณต์กํ ์ถ์ ์์ด์ ํธ ๊ฐ์ฒด๋ฅผ ์ฐ์ง ์๊ณ , ๊ฐ์ฅ ๋ก์ฐ๋ ๋ฒจ์์ ์์ ํ๊ฒ ๋ชจ๋ธ์ ํธ์ถํ๋ ํด๋ผ์ด์ธํธ๋ง ์ฌ์ฉ
|
| 9 |
+
from huggingface_hub import InferenceClient
|
| 10 |
|
| 11 |
# --- Constants ---
|
| 12 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
|
|
| 15 |
# ----- THIS IS WHERE YOU CAN BUILD WHAT YOU WANT ------
|
| 16 |
class BasicAgent:
|
| 17 |
def __init__(self):
|
| 18 |
+
# Hugging Face Spaces ํ๊ฒฝ์ ๊ธฐ๋ณธ ์ ๊ณต๋๋ HF_TOKEN ํ๊ฒฝ ๋ณ์๋ฅผ ์ฌ์ฉํ์ฌ ํด๋ผ์ด์ธํธ ์ธ์ฆ
|
| 19 |
+
self.client = InferenceClient(
|
| 20 |
+
model="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 21 |
+
token=os.getenv("HF_TOKEN")
|
| 22 |
)
|
| 23 |
+
print("BasicAgent initialized with native InferenceClient.")
|
| 24 |
|
| 25 |
def __call__(self, question: str) -> str:
|
| 26 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 27 |
|
| 28 |
try:
|
| 29 |
+
refined_prompt = (
|
| 30 |
+
f"{question}\n\n"
|
| 31 |
+
f"Provide the final answer as briefly as possible at the very end. "
|
| 32 |
+
f"No explanations in the last line."
|
| 33 |
+
)
|
| 34 |
|
| 35 |
+
# ์์ด์ ํธ ๋ฃจํ ์์ด ๋จ๋ฐ์ฑ ํ
์คํธ ์์ฑ์ ์ํํ๋ฏ๋ก ๊ตฌ์กฐ์ ๋ฐํ์ ์๋ฌ๊ฐ ๋ฐ์ํ์ง ์์
|
| 36 |
+
response = self.client.text_generation(
|
| 37 |
+
refined_prompt,
|
| 38 |
+
max_new_tokens=512,
|
| 39 |
+
clean_up_tokenization_spaces=True
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
final_answer = response.strip()
|
| 43 |
print(f"Agent returning answer: {final_answer}")
|
| 44 |
return final_answer
|
| 45 |
|
| 46 |
except Exception as e:
|
| 47 |
+
print(f"Error running model via InferenceClient: {e}")
|
| 48 |
return "unknown"
|
| 49 |
|
| 50 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|