wt002 commited on
Commit
8b86d71
·
verified ·
1 Parent(s): 6c628db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -8,7 +8,7 @@ import requests
8
  from typing import List, Dict, Union
9
  import pandas as pd
10
  import wikipediaapi
11
- #from docx import Document
12
 
13
  load_dotenv()
14
 
@@ -20,7 +20,7 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
20
  # --- Basic Agent Definition ---
21
  class BasicAgent:
22
  def __init__(self, model="google/gemma-7b"):
23
- self.api_url = f"https://api-inference.huggingface.co/models/{model}"
24
  self.headers = {"Authorization": f"Bearer {os.getenv('HF_API_KEY')}"}
25
  # Wikipedia setup (with proper User-Agent)
26
  self.wiki = wikipediaapi.Wikipedia(
@@ -34,10 +34,22 @@ class BasicAgent:
34
 
35
  def __call__(self, question: str) -> str:
36
  print(f"Agent received question (first 50 chars): {question[:50]}...")
37
- fixed_answer = self.generate_response(question)
38
  print(f"Agent returning answer: {fixed_answer}")
39
  return fixed_answer
40
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  def generate_response(self, prompt: str) -> str:
43
  """Get response from HuggingFace model"""
 
8
  from typing import List, Dict, Union
9
  import pandas as pd
10
  import wikipediaapi
11
+ from google import genai
12
 
13
  load_dotenv()
14
 
 
20
  # --- Basic Agent Definition ---
21
  class BasicAgent:
22
  def __init__(self, model="google/gemma-7b"):
23
+ #self.api_url = f"https://api-inference.huggingface.co/models/{model}"
24
  self.headers = {"Authorization": f"Bearer {os.getenv('HF_API_KEY')}"}
25
  # Wikipedia setup (with proper User-Agent)
26
  self.wiki = wikipediaapi.Wikipedia(
 
34
 
35
  def __call__(self, question: str) -> str:
36
  print(f"Agent received question (first 50 chars): {question[:50]}...")
37
+ fixed_answer = self.answer_question(question)
38
  print(f"Agent returning answer: {fixed_answer}")
39
  return fixed_answer
40
 
41
+ def answer_question(self, prompt: str) -> str:
42
+ from google import genai
43
+
44
+ client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))
45
+
46
+ response = client.models.generate_content(
47
+ model="gemini-2.0-flash",
48
+ contents=prompt,
49
+ )
50
+
51
+ return response.text
52
+
53
 
54
  def generate_response(self, prompt: str) -> str:
55
  """Get response from HuggingFace model"""