Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ import wikipediaapi
|
|
9 |
import pandas as pd
|
10 |
from transformers import HuggingFaceAgent
|
11 |
from transformers import pipeline # or HfAgent if you want the higher-level agent
|
12 |
-
|
13 |
|
14 |
load_dotenv()
|
15 |
|
@@ -22,20 +22,23 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
22 |
|
23 |
class BasicAgent:
|
24 |
def __init__(self, model="google/gemma-7b"):
|
25 |
-
#
|
26 |
-
self.agent =
|
|
|
|
|
|
|
27 |
print("BasicAgent initialized.")
|
28 |
|
29 |
def __call__(self, question: str) -> str:
|
30 |
-
print(f"
|
31 |
-
|
32 |
-
|
33 |
-
return
|
34 |
|
35 |
def generate_response(self, prompt: str) -> str:
|
36 |
-
"""Get response from model"""
|
37 |
try:
|
38 |
-
response = self.agent(prompt
|
39 |
return response
|
40 |
except Exception as e:
|
41 |
return f"Error generating response: {str(e)}"
|
|
|
9 |
import pandas as pd
|
10 |
from transformers import HuggingFaceAgent
|
11 |
from transformers import pipeline # or HfAgent if you want the higher-level agent
|
12 |
+
from huggingface_hub import HfAgent
|
13 |
|
14 |
load_dotenv()
|
15 |
|
|
|
22 |
|
23 |
class BasicAgent:
|
24 |
def __init__(self, model="google/gemma-7b"):
|
25 |
+
# Initialize the HF Agent with your model endpoint
|
26 |
+
self.agent = HfAgent(
|
27 |
+
endpoint=f"https://api-inference.huggingface.co/models/{model}",
|
28 |
+
headers={"Authorization": f"Bearer {os.getenv('HF_API_KEY')}"}
|
29 |
+
)
|
30 |
print("BasicAgent initialized.")
|
31 |
|
32 |
def __call__(self, question: str) -> str:
|
33 |
+
print(f"Question: {question[:50]}...")
|
34 |
+
return self.agent.run(question) # For full agent workflow
|
35 |
+
# OR for simple chat:
|
36 |
+
# return self.agent.chat(question)
|
37 |
|
38 |
def generate_response(self, prompt: str) -> str:
|
39 |
+
"""Get response from model using chat interface"""
|
40 |
try:
|
41 |
+
response = self.agent.chat(prompt)
|
42 |
return response
|
43 |
except Exception as e:
|
44 |
return f"Error generating response: {str(e)}"
|