Update app.py
Browse files2 unmodified lines3456781 unmodified line10111213141516171819202122232 unmodified linesimport requestsimport inspectimport pandas as pd# (Keep Constants as is)# --- Constants ---1 unmodified line# --- Basic Agent Definition ---# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------class BasicAgent: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_answerdef run_and_submit_all( profile: gr.OAuthProfile | None):"""2 unmodified lines34567891 unmodified line1112131415161718192021222324252627282930313233343536373839404142434445464748492 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 GeneralAgent:def __init__(self):print("Initializing BERT-based QA agent...")# Cargar el modelo BERT preentrenado en SQuAD para tareas de Pregunta y Respuestaself.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ícitamenteprompt = 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 contextoresult = 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 requeridoreturn f"FINAL ANSWER: {answer}"def run_and_submit_all( profile: gr.OAuthProfile | None):"""
app.py+33-7