Spaces:
Sleeping
Sleeping
Qscar KIM commited on
Commit ยท
359e474
1
Parent(s): 604f0fd
update codes
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import inspect
|
|
| 5 |
import pandas as pd
|
| 6 |
import time
|
| 7 |
|
| 8 |
-
#
|
| 9 |
from huggingface_hub import InferenceClient
|
| 10 |
|
| 11 |
# --- Constants ---
|
|
@@ -14,13 +14,13 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 14 |
# --- Basic Agent Definition ---
|
| 15 |
# ----- THIS IS WHERE YOU CAN BUILD WHAT YOU WANT ------
|
| 16 |
class BasicAgent:
|
| 17 |
-
def __init__(self):
|
| 18 |
-
#
|
| 19 |
self.client = InferenceClient(
|
| 20 |
model="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 21 |
-
token=
|
| 22 |
)
|
| 23 |
-
print("BasicAgent initialized with
|
| 24 |
|
| 25 |
def __call__(self, question: str) -> str:
|
| 26 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
|
@@ -32,10 +32,10 @@ class BasicAgent:
|
|
| 32 |
f"No explanations in the last line."
|
| 33 |
)
|
| 34 |
|
| 35 |
-
# ์์ด์ ํธ
|
| 36 |
response = self.client.text_generation(
|
| 37 |
refined_prompt,
|
| 38 |
-
max_new_tokens=
|
| 39 |
clean_up_tokenization_spaces=True
|
| 40 |
)
|
| 41 |
|
|
@@ -44,7 +44,7 @@ class BasicAgent:
|
|
| 44 |
return final_answer
|
| 45 |
|
| 46 |
except Exception as e:
|
| 47 |
-
print(f"Error running model
|
| 48 |
return "unknown"
|
| 49 |
|
| 50 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
@@ -55,8 +55,10 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 55 |
# --- Determine HF Space Runtime URL and Repo URL ---
|
| 56 |
space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
|
| 57 |
|
|
|
|
| 58 |
if profile:
|
| 59 |
-
username= f"{profile.username}"
|
|
|
|
| 60 |
print(f"User logged in: {username}")
|
| 61 |
else:
|
| 62 |
print("User not logged in.")
|
|
@@ -66,13 +68,13 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 66 |
questions_url = f"{api_url}/questions"
|
| 67 |
submit_url = f"{api_url}/submit"
|
| 68 |
|
| 69 |
-
# 1. Instantiate Agent (
|
| 70 |
try:
|
| 71 |
-
agent = BasicAgent()
|
| 72 |
except Exception as e:
|
| 73 |
print(f"Error instantiating agent: {e}")
|
| 74 |
return f"Error initializing agent: {e}", None
|
| 75 |
-
|
| 76 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 77 |
print(agent_code)
|
| 78 |
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
import time
|
| 7 |
|
| 8 |
+
# ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ถฉ๋๊ณผ ์์ด์ ํธ ๋ฃจํ ์๋ฌ๋ฅผ ๋ฐฉ์งํ๊ธฐ ์ํด ๊ฐ์ฅ ๋ช
ํํ ์ธํผ๋ฐ์ค ํด๋ผ์ด์ธํธ๋ง ์ฌ์ฉ
|
| 9 |
from huggingface_hub import InferenceClient
|
| 10 |
|
| 11 |
# --- Constants ---
|
|
|
|
| 14 |
# --- Basic Agent Definition ---
|
| 15 |
# ----- THIS IS WHERE YOU CAN BUILD WHAT YOU WANT ------
|
| 16 |
class BasicAgent:
|
| 17 |
+
def __init__(self, hf_token: str):
|
| 18 |
+
# ์ ์ ๋ก๊ทธ์ธ์ผ๋ก ๋ฐ์์จ ํ ํฐ์ ๋ค์ด๋ ํธ๋ก ๋ฐ์ธ๋ฉํ์ฌ ์ธ์ฆ ์คํจ๋ฅผ ์์ฒ ์ฐจ๋จ
|
| 19 |
self.client = InferenceClient(
|
| 20 |
model="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 21 |
+
token=hf_token
|
| 22 |
)
|
| 23 |
+
print("BasicAgent initialized with authenticated InferenceClient.")
|
| 24 |
|
| 25 |
def __call__(self, question: str) -> str:
|
| 26 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
|
|
|
| 32 |
f"No explanations in the last line."
|
| 33 |
)
|
| 34 |
|
| 35 |
+
# ์์ด์ ํธ ํ๋ ์์ํฌ์ ๋ฌด๊ฑฐ์ด ์์คํ
ํ๋กฌํํธ ์์ด ์ฆ์ ์ถ๋ก ์ํ
|
| 36 |
response = self.client.text_generation(
|
| 37 |
refined_prompt,
|
| 38 |
+
max_new_tokens=256,
|
| 39 |
clean_up_tokenization_spaces=True
|
| 40 |
)
|
| 41 |
|
|
|
|
| 44 |
return final_answer
|
| 45 |
|
| 46 |
except Exception as e:
|
| 47 |
+
print(f"Error running model: {e}")
|
| 48 |
return "unknown"
|
| 49 |
|
| 50 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
|
|
| 55 |
# --- Determine HF Space Runtime URL and Repo URL ---
|
| 56 |
space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
|
| 57 |
|
| 58 |
+
# ๐ [์ค์] ์ ์ ๋ก๊ทธ์ธ ์ ๋ณด์์ ์ง์ง ํ ํฐ(Oauth Token)์ ๋ฝ์๋
๋๋ค.
|
| 59 |
if profile:
|
| 60 |
+
username = f"{profile.username}"
|
| 61 |
+
hf_token = profile.token # ๋ก๊ทธ์ธํ ์ ์ ์ ์ธ์
ํ ํฐ์ ํ๋ณด
|
| 62 |
print(f"User logged in: {username}")
|
| 63 |
else:
|
| 64 |
print("User not logged in.")
|
|
|
|
| 68 |
questions_url = f"{api_url}/questions"
|
| 69 |
submit_url = f"{api_url}/submit"
|
| 70 |
|
| 71 |
+
# 1. Instantiate Agent (ํ๋ณด๋ ์ง์ง ํ ํฐ์ ์ฃผ์
ํฉ๋๋ค)
|
| 72 |
try:
|
| 73 |
+
agent = BasicAgent(hf_token=hf_token)
|
| 74 |
except Exception as e:
|
| 75 |
print(f"Error instantiating agent: {e}")
|
| 76 |
return f"Error initializing agent: {e}", None
|
| 77 |
+
|
| 78 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 79 |
print(agent_code)
|
| 80 |
|