Spaces:
Build error
Build error
| import os | |
| from langchain.tools import tool | |
| def read_python(file_path): | |
| """ | |
| Reads a Python file and returns its content as a string. | |
| Args: | |
| file_path (str): The path to the Python file. | |
| Returns: | |
| str: The content of the Python file. | |
| """ | |
| try: | |
| if not os.path.exists(file_path): | |
| return f"Error: File not found at {file_path}" | |
| with open(file_path, "r", encoding="utf-8") as file: | |
| content = file.read() | |
| return content | |
| except Exception as e: | |
| return f"Error reading Python file: {str(e)}" | |
| def read_excel(file_path): | |
| """ | |
| Reads an Excel file and returns its content as a string. | |
| Args: | |
| file_path (str): The path to the Excel file. | |
| Returns: | |
| str: The content of the Excel file. | |
| """ | |
| if not file_path.endswith(('.xls', '.xlsx')): | |
| return "Error: File is not an Excel file." | |
| try: | |
| if not os.path.exists(file_path): | |
| return f"Error: File not found at {file_path}" | |
| import pandas as pd | |
| df = pd.read_excel(file_path) | |
| return df.to_string() | |
| except Exception as e: | |
| return f"Error reading Excel file: {str(e)}" | |
| def transcribe_audio(file_path): | |
| """ | |
| Transcribes an audio file and returns its content as a string. | |
| Args: | |
| file_path (str): The path to the audio file. | |
| Returns: | |
| str: The transcribed text from the audio file. | |
| """ | |
| if not file_path.endswith(('.wav', '.mp3', '.m4a')): | |
| return "Error: File is not an audio file." | |
| try: | |
| if not os.path.exists(file_path): | |
| return f"Error: File not found at {file_path}" | |
| import whisper | |
| model = whisper.load_model("base") | |
| result = model.transcribe(file_path, language="en") | |
| text = result["text"] | |
| return text | |
| except Exception as e: | |
| return f"Error transcribing audio file: {str(e)}" |