Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,42 +11,29 @@ load_dotenv()
|
|
11 |
# Constants
|
12 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
13 |
|
14 |
-
# CrewAI components (
|
15 |
-
|
16 |
-
|
17 |
-
self.role = "Researcher"
|
18 |
-
self.goal = "Research information thoroughly"
|
19 |
-
|
20 |
-
def research(self, question):
|
21 |
-
# Implement research logic here
|
22 |
-
return f"Researched information about: {question}"
|
23 |
-
|
24 |
-
class WritingAgent:
|
25 |
-
def __init__(self):
|
26 |
-
self.role = "Writer"
|
27 |
-
self.goal = "Write clear and accurate answers"
|
28 |
-
|
29 |
-
def write(self, research_data):
|
30 |
-
# Implement writing logic here
|
31 |
-
return f"Comprehensive answer based on: {research_data}"
|
32 |
|
33 |
-
# Enhanced Agent Definition
|
34 |
class CrewAIAgent:
|
35 |
def __init__(self):
|
36 |
print("Initializing CrewAI agents...")
|
37 |
-
self.
|
38 |
-
|
|
|
|
|
|
|
|
|
39 |
print("CrewAI agents initialized.")
|
40 |
|
41 |
def __call__(self, question: str) -> str:
|
42 |
print(f"Processing question: {question[:50]}...")
|
43 |
|
44 |
-
# Create and execute crew
|
45 |
try:
|
46 |
-
|
47 |
-
|
48 |
-
print(f"Generated answer: {
|
49 |
-
return
|
50 |
except Exception as e:
|
51 |
print(f"CrewAI error: {e}")
|
52 |
return f"CrewAI Error: {str(e)}"
|
@@ -57,7 +44,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
57 |
|
58 |
# Initialize agent
|
59 |
try:
|
60 |
-
agent = CrewAIAgent()
|
61 |
except Exception as e:
|
62 |
return f"Agent initialization failed: {e}", None
|
63 |
|
|
|
11 |
# Constants
|
12 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
13 |
|
14 |
+
# Import your CrewAI components (assuming they're in separate files)
|
15 |
+
from agents import news_researcher, news_writer
|
16 |
+
from tasks import research_task, write_task
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
|
|
18 |
class CrewAIAgent:
|
19 |
def __init__(self):
|
20 |
print("Initializing CrewAI agents...")
|
21 |
+
self.crew = Crew(
|
22 |
+
agents=[news_researcher, news_writer],
|
23 |
+
tasks=[research_task, write_task],
|
24 |
+
process=Process.sequential,
|
25 |
+
verbose=True
|
26 |
+
)
|
27 |
print("CrewAI agents initialized.")
|
28 |
|
29 |
def __call__(self, question: str) -> str:
|
30 |
print(f"Processing question: {question[:50]}...")
|
31 |
|
|
|
32 |
try:
|
33 |
+
# Execute the crew with the question as input
|
34 |
+
result = self.crew.kickoff(inputs={'topic': question})
|
35 |
+
print(f"Generated answer: {result[:100]}...")
|
36 |
+
return str(result)
|
37 |
except Exception as e:
|
38 |
print(f"CrewAI error: {e}")
|
39 |
return f"CrewAI Error: {str(e)}"
|
|
|
44 |
|
45 |
# Initialize agent
|
46 |
try:
|
47 |
+
agent = CrewAIAgent()
|
48 |
except Exception as e:
|
49 |
return f"Agent initialization failed: {e}", None
|
50 |
|