Spaces:
Sleeping
Sleeping
Update agent.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738from 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(), trace1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950import osimport mimetypesfrom transformers import pipelinefrom tools.asr_tool import transcribe_audiofrom tools.excel_tool import analyze_excelfrom tools.search_tool import search_duckduckgoclass GaiaAgent:def __init__(self):token = os.getenv("HUGGINGFACEHUB_API_TOKEN")if not token:raise ValueError("Missing HUGGINGFACEHUB_API_TOKEN environment variable.")self.llm = pipeline("text-generation",model="mistralai/Mistral-7B-Instruct-v0.2",token=token,device="cpu",max_new_tokens=512,do_sample=False)def __call__(self, question: str):trace_log = ""if "http" in question or "www." in question:trace_log += "Detected URL or web reference. Performing search...\n"result = search_duckduckgo(question)trace_log += f"Search result: {result}\n"return result, trace_logif question.lower().endswith(".mp3") or question.lower().endswith(".wav"):trace_log += "Detected audio file. Performing transcription...\n"result = transcribe_audio(question)trace_log += f"Transcription result: {result}\n"return result, trace_logif question.lower().endswith(".xlsx") or question.lower().endswith(".xls"):trace_log += "Detected Excel file. Performing analysis...\n"result = analyze_excel(question)trace_log += f"Excel analysis result: {result}\n"return result, trace_logtrace_log += "General question. Using local model...\n"response = self.llm(question)[0]["generated_text"]trace_log += f"LLM response: {response}\n"return response.strip(), trace_log
agent.py+34-22