Spaces:
Sleeping
Sleeping
Update app.py
Browse files2 unmodified lines34567891 unmodified line111213131415151617181920161718192021222324252627282930313233343536373839404142434445464748492 unmodified linesimport requestsimport inspectimport pandas as pdimport transfomers
# (Keep Constants as is)# --- Constants ---1 unmodified line
# --- Basic Agent Definition ---# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------class BasicAgent:class GeneralAgent: def __init__(self): print("BasicAgent initialized.") def __call__(self, question: str) -> str: print(f"Agent received question (first 50 chars): {question[:50]}...") fixed_answer = "This is a default answer." print(f"Agent returning fixed answer: {fixed_answer}") return fixed_answer print("Initializing BERT-based QA agent...") # Cargar el modelo BERT preentrenado en SQuAD para tareas de Pregunta y Respuesta self.qa_pipeline = pipeline("question-answering", model="bert-large-uncased-whole-word-masking-finetuned-squad") def __call__(self, question: str, context: str = None) -> str: """ Procesa la pregunta y devuelve una respuesta basada en el contexto proporcionado. Si no se proporciona contexto, devuelve un mensaje de error. """ if context is None: return "FINAL ANSWER: No context provided." # Crear un prompt dentro del contexto que estructure la tarea más explícitamente prompt = f"""You are a general AI assistant. I will ask you a question based on the provided context. Please provide the answer in a clear and concise manner.Question: {question}Context: {context}Answer:""" try: # Usar el pipeline para obtener la respuesta de la pregunta con el contexto result = self.qa_pipeline(question=question, context=prompt) answer = result["answer"] except Exception as e: print(f"Error durante QA: {e}") answer = "Error processing question." # Devuelve la respuesta final con el formato requerido return f"FINAL ANSWER: {answer}"
def run_and_submit_all( profile: gr.OAuthProfile | None): """app.py+33-7