Spaces:
Sleeping
Sleeping
Update app.py
Browse files13 unmodified lines141516171819202122232425262728293031323334353637383913 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 clear and structured prompt, and return an answer."""# Create a clearer and more direct promptprompt = f"Answer the following question: {question}"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):"""Fetches all questions, runs the BasicAgent on them, submits all answers,13 unmodified lines1415161718192021222324252627282930313233343536373813 unmodified lines# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------class BasicAgent:def __init__(self):print("Initializing BERT-based QA agent...")# Load the BERT model fine-tuned on the SQuAD datasetself.qa_pipeline = pipeline("question-answering", model="bert-large-uncased-whole-word-masking-finetuned-squad")def __call__(self, question: str, context: str) -> str:"""Process the question using the BERT model fine-tuned on SQuAD, and return an answer based on the context."""try:# Use the QA pipeline to get an answer based on the context and the questionresult = self.qa_pipeline(question=question, context=context)answer = result["answer"]except Exception as e:print(f"Error during QA: {e}")answer = "Error processing question."return answerdef run_and_submit_all( profile: gr.OAuthProfile | None):"""Fetches all questions, runs the BasicAgent on them, submits all answers,
app.py+10-11