rnrahate007 commited on
Commit
80db5ce
·
verified ·
1 Parent(s): 5a865d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -21
app.py CHANGED
@@ -12,41 +12,47 @@ GEMINI_MODEL = "gemini-2.5-flash-lite" # Fast, cost-effective model
12
  # --- Gemini Agent Definition ---
13
  class GeminiAgent:
14
  def __init__(self):
15
- api_key = os.getenv("GEMINI_API_KEY")
16
  if not api_key:
17
- raise ValueError("GEMINI_API_KEY environment variable not set. Please set it before running.")
18
- genai.configure(api_key=api_key)
19
- self.model = genai.GenerativeModel(GEMINI_MODEL)
20
- print(f"GeminiAgent initialized with model {GEMINI_MODEL}.")
 
 
21
 
22
  def __call__(self, question: str) -> str:
23
- print(f"GeminiAgent received question (first 50 chars): {question[:50]}...")
24
- # Prompt engineered for GAIA's answer format (short, factual, unambiguous)
25
  prompt = f"""
26
- You are an expert assistant for the GAIA benchmark.
27
- Provide a short, factual, and unambiguous answer to the following question.
28
- Your answer should be a number, a short string, or a comma-separated list.
29
- Do not use phrases like "I don't know", "NA", "not applicable", or leave the answer empty.
30
- Avoid giving a step-by-step explanation in your final answer.
31
 
32
- Question: {question}
 
 
 
33
 
34
- Final Answer:
35
- """
36
  try:
37
  time.sleep(6)
38
 
39
- response = self.model.generate_content(prompt)
40
- answer = response.text.strip()
 
 
 
 
 
 
 
41
 
42
- # simple clean (NO second call)
43
  if not answer:
44
- answer = "0" # or any short default
45
 
46
  return answer
 
47
  except Exception as e:
48
- print(f"Gemini API error: {e}")
49
- # Last resort: return a non-empty, generic answer (should rarely happen)
50
  return f"Error occurred: {e}"
51
 
52
  def run_and_submit_all(profile: gr.OAuthProfile | None):
 
12
  # --- Gemini Agent Definition ---
13
  class GeminiAgent:
14
  def __init__(self):
15
+ api_key = os.getenv("GEMINI_API_KEY") # keep same secret
16
  if not api_key:
17
+ raise ValueError("GEMINI_API_KEY not set")
18
+
19
+ self.client = Groq(api_key=api_key)
20
+ self.model = "llama3-70b-8192"
21
+
22
+ print("Groq Agent initialized")
23
 
24
  def __call__(self, question: str) -> str:
25
+ print(f"GeminiAgent received question: {question[:50]}...")
26
+
27
  prompt = f"""
28
+ You are an expert assistant for the GAIA benchmark.
29
+ Provide a short, factual answer.
 
 
 
30
 
31
+ Question: {question}
32
+
33
+ Final Answer:
34
+ """
35
 
 
 
36
  try:
37
  time.sleep(6)
38
 
39
+ response = self.client.chat.completions.create(
40
+ model=self.model,
41
+ messages=[
42
+ {"role": "user", "content": prompt}
43
+ ],
44
+ temperature=0
45
+ )
46
+
47
+ answer = response.choices[0].message.content.strip()
48
 
 
49
  if not answer:
50
+ answer = "0"
51
 
52
  return answer
53
+
54
  except Exception as e:
55
+ print("Groq API error:", e)
 
56
  return f"Error occurred: {e}"
57
 
58
  def run_and_submit_all(profile: gr.OAuthProfile | None):