vijaya01 commited on
Commit
8ff2f36
·
verified ·
1 Parent(s): aea253f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -16
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 Agent initializing...")
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 general knowledge and reasoning-based questions accurately.",
27
- backstory="You are an expert agent trained in logical reasoning, trivia, and general facts. Your job is to produce accurate answers to benchmark questions.",
 
 
 
28
  allow_delegation=False,
29
  verbose=True,
30
  llm=self.llm,
31
-
32
  )
 
33
  def __call__(self, question: str) -> str:
34
- print(f"Agent received question: {question[:50]}...")
35
  task = Task(
36
- description=f"Answer the following question clearly and concisely:\n\n{question}",
37
- expected_output="A single sentence or paragraph with the correct answer.",
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"Agent result: {result}")
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
  """