Update app.py
Browse files
app.py
CHANGED
|
@@ -12,8 +12,9 @@ from langchain_openai import ChatOpenAI
|
|
| 12 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 13 |
HUGGINGFACEHUB_API_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
| 14 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 15 |
-
# REPO_ID = "Qwen/Qwen2.5-Coder-7B-Instruct"
|
| 16 |
REPO_ID = "meta-llama/Llama-3.1-8B-Instruct"
|
|
|
|
|
|
|
| 17 |
|
| 18 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 19 |
"""
|
|
@@ -34,17 +35,26 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 34 |
questions_url = f"{api_url}/questions"
|
| 35 |
submit_url = f"{api_url}/submit"
|
| 36 |
|
| 37 |
-
# 1. Instantiate Agent
|
| 38 |
try:
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
except Exception as e:
|
| 45 |
print(f"Error instantiating agent: {e}")
|
| 46 |
return f"Error initializing agent: {e}", None
|
| 47 |
-
|
|
|
|
| 48 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 49 |
print(agent_code)
|
| 50 |
|
|
@@ -147,14 +157,13 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 147 |
|
| 148 |
# --- Build Gradio Interface using Blocks ---
|
| 149 |
with gr.Blocks() as demo:
|
| 150 |
-
gr.Markdown("#
|
| 151 |
gr.Markdown(
|
| 152 |
"""
|
| 153 |
**Instructions:**
|
| 154 |
|
| 155 |
-
1.
|
| 156 |
-
2.
|
| 157 |
-
3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
|
| 158 |
|
| 159 |
---
|
| 160 |
**Disclaimers:**
|
|
|
|
| 12 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 13 |
HUGGINGFACEHUB_API_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
| 14 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
|
|
|
| 15 |
REPO_ID = "meta-llama/Llama-3.1-8B-Instruct"
|
| 16 |
+
PROVIDER_TYPE = "openai" # "openai" or "huggingface"
|
| 17 |
+
|
| 18 |
|
| 19 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 20 |
"""
|
|
|
|
| 35 |
questions_url = f"{api_url}/questions"
|
| 36 |
submit_url = f"{api_url}/submit"
|
| 37 |
|
| 38 |
+
# 1. Instantiate Agent
|
| 39 |
try:
|
| 40 |
+
if PROVIDER_TYPE=="huggingface":
|
| 41 |
+
llm = HuggingFaceEndpoint(
|
| 42 |
+
repo_id=REPO_ID,
|
| 43 |
+
huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN,
|
| 44 |
+
)
|
| 45 |
+
chat = ChatHuggingFace(llm=llm, verbose=True)
|
| 46 |
+
elif PROVIDER_TYPE=="openai":
|
| 47 |
+
chat = ChatOpenAI(model="gpt-4o")
|
| 48 |
+
else:
|
| 49 |
+
print(f"Provider {PROVIDER_TYPE} not supported.")
|
| 50 |
+
return f"Provider {PROVIDER_TYPE} not supported", None
|
| 51 |
+
agent = BasicAgent(chat)
|
| 52 |
+
|
| 53 |
except Exception as e:
|
| 54 |
print(f"Error instantiating agent: {e}")
|
| 55 |
return f"Error initializing agent: {e}", None
|
| 56 |
+
|
| 57 |
+
# In the case of an app running as a hugging Face space, this link points toward your codebase
|
| 58 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 59 |
print(agent_code)
|
| 60 |
|
|
|
|
| 157 |
|
| 158 |
# --- Build Gradio Interface using Blocks ---
|
| 159 |
with gr.Blocks() as demo:
|
| 160 |
+
gr.Markdown("# Agent Evaluation Runner")
|
| 161 |
gr.Markdown(
|
| 162 |
"""
|
| 163 |
**Instructions:**
|
| 164 |
|
| 165 |
+
1. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
|
| 166 |
+
2. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
|
|
|
|
| 167 |
|
| 168 |
---
|
| 169 |
**Disclaimers:**
|