Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +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 ---
|
|
@@ -12,12 +13,30 @@ 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 |
-
print(f"
|
| 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 |
+
import openai
|
| 7 |
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
|
|
|
| 13 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 14 |
class BasicAgent:
|
| 15 |
def __init__(self):
|
| 16 |
+
self.api_key = os.getenv("OPENAI_API_KEY")
|
| 17 |
+
if not self.api_key:
|
| 18 |
+
raise ValueError("OpenAI API key not found. Please set OPENAI_API_KEY as environment variable.")
|
| 19 |
+
openai.api_key = self.api_key
|
| 20 |
+
print("🔑 OpenAI Agent initialized.")
|
| 21 |
+
|
| 22 |
def __call__(self, question: str) -> str:
|
| 23 |
+
print(f"❓ Question received: {question[:50]}...")
|
| 24 |
+
try:
|
| 25 |
+
response = openai.ChatCompletion.create(
|
| 26 |
+
model="gpt-3.5-turbo", # or "gpt-4" if you have access
|
| 27 |
+
messages=[
|
| 28 |
+
{"role": "system", "content": "You are a helpful assistant that answers GAIA benchmark questions."},
|
| 29 |
+
{"role": "user", "content": question}
|
| 30 |
+
],
|
| 31 |
+
max_tokens=300,
|
| 32 |
+
temperature=0.7
|
| 33 |
+
)
|
| 34 |
+
answer = response["choices"][0]["message"]["content"].strip()
|
| 35 |
+
print(f"✅ Answer: {answer}")
|
| 36 |
+
return answer
|
| 37 |
+
except Exception as e:
|
| 38 |
+
print(f"❌ Error calling OpenAI API: {e}")
|
| 39 |
+
return f"ERROR: {e}"
|
| 40 |
|
| 41 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 42 |
"""
|