Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,8 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
|
@@ -13,11 +15,24 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 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 |
-
|
| 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 huggingface_hub import InferenceClient
|
| 7 |
+
import os
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
|
|
|
| 15 |
class BasicAgent:
|
| 16 |
def __init__(self):
|
| 17 |
print("BasicAgent initialized.")
|
| 18 |
+
self.client = InferenceClient(
|
| 19 |
+
token=os.getenv("HF_TOKEN")
|
| 20 |
+
)
|
| 21 |
def __call__(self, question: str) -> str:
|
| 22 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 23 |
+
response = self.client.chat_completion(
|
| 24 |
+
model="meta-llama/Llama-3.1-8B-Instruct",
|
| 25 |
+
messages=[
|
| 26 |
+
{"role": "user", "content": question}
|
| 27 |
+
],
|
| 28 |
+
max_tokens=512
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
return response.choices[0].message.content
|
| 32 |
+
|
| 33 |
+
# fixed_answer = "This is a default answer."
|
| 34 |
+
# print(f"Agent returning fixed answer: {fixed_answer}")
|
| 35 |
+
# return fixed_answer
|
| 36 |
|
| 37 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 38 |
"""
|