Spaces:
Sleeping
Sleeping
Update app.py
Browse files13 unmodified lines14151617181920212223242526272829303132333435363738394041424344454647484913 unmodified lines# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------class BasicAgent: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) -> str:"""Procesa la pregunta y devuelve una respuesta basada en el contexto proporcionado.Si no se proporciona contexto, devuelve un mensaje de error."""prompt = """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."""# 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: {prompt}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 answerdef run_and_submit_all( profile: gr.OAuthProfile | None):13 unmodified lines141516171819202122232425262728293031323334353637383940414213 unmodified lines# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------class BasicAgent:def __init__(self):print("Initializing T5-based QA agent with custom prompt...")# Load the T5 modelself.qa_pipeline = pipeline("text2text-generation", model="t5-large")def __call__(self, question: str) -> str:"""Process the question using T5 with a detailed prompt and return an answer."""# Create a more structured and detailed promptprompt = f"""You are an intelligent assistant. Please answer the following question as accurately as possible:Question: {question}Answer:"""try:# Use the T5 pipeline to generate an answerresult = self.qa_pipeline(prompt)answer = result[0]["generated_text"].strip()except Exception as e:print(f"Error during QA: {e}")answer = "Error processing question."return answerdef run_and_submit_all( profile: gr.OAuthProfile | None):
app.py+13-20