Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,26 +2,24 @@ import os
|
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
import pandas as pd
|
| 5 |
-
from
|
| 6 |
-
from agent import build_graph
|
| 7 |
|
| 8 |
# --- Constants ---
|
| 9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
-
|
| 13 |
-
"""A langgraph agent."""
|
| 14 |
def __init__(self):
|
| 15 |
-
print("
|
| 16 |
-
self.
|
|
|
|
| 17 |
|
| 18 |
def __call__(self, question: str) -> str:
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
return answer[14:]
|
| 25 |
|
| 26 |
# --- Helper Functions ---
|
| 27 |
def fetch_questions(api_url: str):
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
import pandas as pd
|
| 5 |
+
from transformers import pipeline
|
|
|
|
| 6 |
|
| 7 |
# --- Constants ---
|
| 8 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 9 |
|
| 10 |
# --- Basic Agent Definition ---
|
| 11 |
+
class BasicAgent:
|
|
|
|
| 12 |
def __init__(self):
|
| 13 |
+
print("Loading FLAN-T5 model...")
|
| 14 |
+
self.model = pipeline("text2text-generation", model="google/flan-t5-base", max_length=256)
|
| 15 |
+
print("Model loaded.")
|
| 16 |
|
| 17 |
def __call__(self, question: str) -> str:
|
| 18 |
+
prompt = f"Answer the following question accurately and concisely:\n{question.strip()}"
|
| 19 |
+
result = self.model(prompt)
|
| 20 |
+
answer = result[0]['generated_text'].strip()
|
| 21 |
+
print(f"Answer generated: {answer}")
|
| 22 |
+
return answer
|
|
|
|
| 23 |
|
| 24 |
# --- Helper Functions ---
|
| 25 |
def fetch_questions(api_url: str):
|