Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,8 +3,10 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
|
|
|
| 6 |
from crewai import Crew, Agent, Task
|
| 7 |
from langchain_openai import ChatOpenAI
|
|
|
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
|
@@ -14,37 +16,36 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 14 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 15 |
|
| 16 |
|
|
|
|
| 17 |
class BasicAgent:
|
| 18 |
def __init__(self):
|
| 19 |
-
print("CrewAI
|
| 20 |
-
|
| 21 |
self.llm = ChatOpenAI(model="gpt-4", temperature=0.3)
|
| 22 |
|
| 23 |
-
# Define a single agent
|
| 24 |
self.agent = Agent(
|
| 25 |
role="QA Specialist",
|
| 26 |
-
goal="Answer
|
| 27 |
-
backstory=
|
|
|
|
|
|
|
|
|
|
| 28 |
allow_delegation=False,
|
| 29 |
verbose=True,
|
| 30 |
llm=self.llm,
|
| 31 |
-
|
| 32 |
)
|
|
|
|
| 33 |
def __call__(self, question: str) -> str:
|
| 34 |
-
print(f"
|
| 35 |
task = Task(
|
| 36 |
-
description=f"Answer the following question
|
| 37 |
-
expected_output="
|
| 38 |
agent=self.agent
|
| 39 |
)
|
| 40 |
-
crew = Crew(
|
| 41 |
-
agents=[self.agent],
|
| 42 |
-
tasks=[task],
|
| 43 |
-
verbose=False,
|
| 44 |
-
)
|
| 45 |
result = crew.kickoff()
|
| 46 |
-
print(f"
|
| 47 |
-
return result
|
|
|
|
| 48 |
|
| 49 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 50 |
"""
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
|
| 7 |
from crewai import Crew, Agent, Task
|
| 8 |
from langchain_openai import ChatOpenAI
|
| 9 |
+
import os
|
| 10 |
|
| 11 |
# (Keep Constants as is)
|
| 12 |
# --- Constants ---
|
|
|
|
| 16 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 17 |
|
| 18 |
|
| 19 |
+
|
| 20 |
class BasicAgent:
|
| 21 |
def __init__(self):
|
| 22 |
+
print("✅ Initializing CrewAI agent...")
|
|
|
|
| 23 |
self.llm = ChatOpenAI(model="gpt-4", temperature=0.3)
|
| 24 |
|
|
|
|
| 25 |
self.agent = Agent(
|
| 26 |
role="QA Specialist",
|
| 27 |
+
goal="Answer benchmark questions accurately with deep reasoning and knowledge",
|
| 28 |
+
backstory=(
|
| 29 |
+
"You are a highly intelligent AI developed to answer a wide range of reasoning, general knowledge, and logic-based benchmark questions. "
|
| 30 |
+
"Your goal is to provide concise and correct answers to academic and real-world challenges."
|
| 31 |
+
),
|
| 32 |
allow_delegation=False,
|
| 33 |
verbose=True,
|
| 34 |
llm=self.llm,
|
|
|
|
| 35 |
)
|
| 36 |
+
|
| 37 |
def __call__(self, question: str) -> str:
|
| 38 |
+
print(f"📥 Received question: {question[:60]}...")
|
| 39 |
task = Task(
|
| 40 |
+
description=f"Answer the following question as accurately and clearly as possible:\n\n{question}",
|
| 41 |
+
expected_output="The correct answer in one or two sentences.",
|
| 42 |
agent=self.agent
|
| 43 |
)
|
| 44 |
+
crew = Crew(agents=[self.agent], tasks=[task], verbose=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
result = crew.kickoff()
|
| 46 |
+
print(f"📤 Returning result: {result}")
|
| 47 |
+
return result.strip()
|
| 48 |
+
|
| 49 |
|
| 50 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 51 |
"""
|