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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -5
app.py CHANGED
@@ -3,6 +3,8 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
 
 
6
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
@@ -10,14 +12,39 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
  # --- Basic Agent Definition ---
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
 
 
13
  class BasicAgent:
14
  def __init__(self):
15
- print("BasicAgent initialized.")
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  def __call__(self, question: str) -> str:
17
- print(f"Agent received question (first 50 chars): {question[:50]}...")
18
- fixed_answer = "This is a default answer."
19
- print(f"Agent returning fixed answer: {fixed_answer}")
20
- return fixed_answer
 
 
 
 
 
 
 
 
 
 
21
 
22
  def run_and_submit_all( profile: gr.OAuthProfile | None):
23
  """
 
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 ---
 
12
 
13
  # --- Basic Agent Definition ---
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
  """