Spaces:
Sleeping
Sleeping
Update agent.py
Browse files123458 unmodified lines141516171819201 unmodified line2223242526272829303132333435363738394041424344454647484950import osimport mimetypesfrom transformers import pipelinefrom tools.asr_tool import transcribe_audiofrom tools.excel_tool import analyze_excel8 unmodified linesself.llm = pipeline("text-generation",model="mistralai/Mistral-7B-Instruct-v0.2",token=token,device="cpu",max_new_tokens=512,do_sample=False1 unmodified linedef __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_log12348 unmodified lines131415161718191 unmodified line21222324252627282930313233343536373839404142434445464748495051import osfrom transformers import pipelinefrom tools.asr_tool import transcribe_audiofrom tools.excel_tool import analyze_excel8 unmodified linesself.llm = pipeline("text-generation",model="mistralai/Mistral-7B-Instruct-v0.2",use_auth_token=token,device="cpu",max_new_tokens=512,do_sample=False1 unmodified linedef __call__(self, question: str):trace_log = ""# Search toolif "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_log# Audio toolif 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_log# Excel toolif 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_log# LLM fallbacktrace_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+5-4