Spaces:
Sleeping
Sleeping
Update agent.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243from transformers import pipelinefrom tools.asr_tool import transcribe_audiofrom tools.excel_tool import analyze_excelfrom tools.search_tool import search_duckduckgoimport mimetypesclass GaiaAgent:def __init__(self):print("Loading model...")self.model = pipeline("text2text-generation",model="MBZUAI/LaMini-Flan-T5-783M",tokenizer="MBZUAI/LaMini-Flan-T5-783M")print("Model loaded.")def __call__(self, query):trace = ""final_answer = ""# Försök identifiera om det är en filreferensif isinstance(query, str) and (query.endswith(".mp3") or query.endswith(".wav")):trace = "Detected audio file. Transcribing..."final_answer = transcribe_audio(query)elif isinstance(query, str) and (query.endswith(".xls") or query.endswith(".xlsx")):trace = "Detected Excel file. Analyzing..."final_answer = analyze_excel(query)elif "http" in query:trace = "Detected URL or web reference. Performing search..."final_answer = search_duckduckgo(query)else:trace = "General question. Using local model..."output = self.model(query, max_new_tokens=128)final_answer = output[0]["generated_text"].strip()return final_answer, trace1234567891011121314151617181920212223242526272829303132333435363738from transformers import pipelinefrom tools.search_tool import search_duckduckgofrom tools.asr_tool import transcribe_audiofrom tools.excel_tool import analyze_excelclass GaiaAgent:def __init__(self):self.llm = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.2", device="cpu")def __call__(self, question: str):trace = ""question_lower = question.lower()if "http" in question_lower or "wikipedia" in question_lower:trace += "Detected URL or web reference. Performing search...\n"result = search_duckduckgo(question)trace += resultreturn result.strip(), traceelif question_lower.endswith(".mp3"):trace += "Detected audio reference. Transcribing audio...\n"result = transcribe_audio(question)trace += resultreturn result.strip(), traceelif question_lower.endswith(".xlsx") or question_lower.endswith(".csv"):trace += "Detected Excel file. Analyzing...\n"result = analyze_excel(question)trace += resultreturn result.strip(), traceelse:trace += "General question. Using local model...\n"output = self.llm(question, max_new_tokens=256, do_sample=False)[0]["generated_text"]trace += outputreturn output.strip(), trace
agent.py+26-31