Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,12 +12,35 @@ 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 |
-
print("
|
|
|
|
|
|
|
| 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 |
"""
|
|
|
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
+
print("WolfarmAlpha Agent Initialized")
|
| 16 |
+
self.app_id = os.getenv("WOLFARM_APP_ID")
|
| 17 |
+
|
| 18 |
def __call__(self, question: str) -> str:
|
| 19 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 20 |
+
if not self.app_id:
|
| 21 |
+
print("WolfarmAlpha ID not found.")
|
| 22 |
+
return "Error : WolfarmAlpha ID not set."
|
| 23 |
+
|
| 24 |
+
try :
|
| 25 |
+
url = "http://api.wolframalpha.com/v1/result"
|
| 26 |
+
params = {
|
| 27 |
+
"i" : question
|
| 28 |
+
"appid" : self.app_id
|
| 29 |
+
}
|
| 30 |
+
response = requests.get(url, params = params, timeout=10)
|
| 31 |
+
|
| 32 |
+
if response.status_code == 200:
|
| 33 |
+
print("WolfarmAlpha Response Affirmative.")
|
| 34 |
+
return response.text
|
| 35 |
+
|
| 36 |
+
else :
|
| 37 |
+
print(f"WolfarmAlpha Status Update {response.status_code}")
|
| 38 |
+
return f"Couldn't retreive a response from WolfarmAlpha. Status{response.status_code} "
|
| 39 |
+
|
| 40 |
+
except Exception as e:
|
| 41 |
+
print(f"Execption calling WolfarmAlpha: {e}")
|
| 42 |
+
return f"Error Retrieveing WolfarmAlpha API: {e}"
|
| 43 |
+
|
| 44 |
|
| 45 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 46 |
"""
|