DrekFretson commited on
Commit
7f3eba6
·
verified ·
1 Parent(s): 747710e

Delete tools.py

Browse files
Files changed (1) hide show
  1. tools.py +0 -85
tools.py DELETED
@@ -1,85 +0,0 @@
1
- import base64
2
- from openai import OpenAI
3
- from smolagents import tool
4
- import pandas as pd
5
- import os
6
-
7
- OPEN_AI_CLIENT = OpenAI()
8
-
9
-
10
- @tool
11
- def extract_data(filename: str) -> str:
12
- """
13
- Extracts data from an Excel file and returns it as a CSV-formatted string.
14
- Args:
15
- filename: The path to the Excel file to extract data from.
16
- Returns:
17
- str: The extracted data in CSV format or an error message.
18
- Raises:
19
- Exception: If there is an issue with reading the Excel file.
20
- """
21
- try:
22
- df = pd.read_excel(filename)
23
- return df.to_csv(index=False)
24
- except Exception as e:
25
- return f"Error extracting data from Excel: {str(e)}"
26
-
27
-
28
- @tool
29
- def transcribe_mp3(filename: str) -> str:
30
- """
31
- Transcribes speech from an MP3 file using the OpenAI Whisper API.
32
- Args:
33
- filename: The path to the MP3 file to transcribe.
34
- Returns:
35
- str: The transcribed text or an error message.
36
- Raises:
37
- Exception: If there is an issue with the transcription process.
38
- """
39
-
40
- try:
41
- with open(filename, "rb") as audio_file:
42
- transcript = OPEN_AI_CLIENT.audio.transcriptions.create(
43
- model="whisper-1", file=audio_file
44
- )
45
- return transcript.text
46
- except Exception as e:
47
- return f"Error transcribing audio: {str(e)}"
48
-
49
-
50
- @tool
51
- def describe_image(prompt: str, filename: str) -> str:
52
- """
53
- Describes the content of an image using the OpenAI Vision API.
54
- Args:
55
- prompt: A prompt to guide the description.
56
- filename: The path to the image file to describe.
57
- Returns:
58
- str: The description of the image or an error message.
59
- Raises:
60
- Exception: If there is an issue with the description process.
61
- """
62
-
63
- try:
64
- with open(filename, "rb") as image_file:
65
- base64_image = base64.b64encode(image_file.read()).decode("utf-8")
66
-
67
- response = OPEN_AI_CLIENT.responses.create(
68
- model="gpt-4.1",
69
- input=[
70
- {
71
- "role": "user",
72
- "content": [
73
- {"type": "input_text", "text": prompt},
74
- {
75
- "type": "input_image",
76
- "image_url": f"data:image/jpeg;base64,{base64_image}",
77
- },
78
- ],
79
- }
80
- ],
81
- )
82
- return response.output_text
83
-
84
- except Exception as e:
85
- return f"Error describing image: {str(e)}"