-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasksB.py
More file actions
93 lines (83 loc) · 2.71 KB
/
tasksB.py
File metadata and controls
93 lines (83 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Phase B: LLM-based Automation Agent for DataWorks Solutions
# B1 & B2: Security Checks
import os
def B12(filepath):
if filepath.startswith('/data'):
# raise PermissionError("Access outside /data is not allowed.")
# print("Access outside /data is not allowed.")
return True
else:
return False
# B3: Fetch Data from an API
def B3(url, save_path):
if not B12(save_path):
return None
import requests
response = requests.get(url)
with open(save_path, 'w') as file:
file.write(response.text)
# B4: Clone a Git Repo and Make a Commit
# def clone_git_repo(repo_url, commit_message):
# import subprocess
# subprocess.run(["git", "clone", repo_url, "/data/repo"])
# subprocess.run(["git", "-C", "/data/repo", "commit", "-m", commit_message])
# B5: Run SQL Query
def B5(db_path, query, output_filename):
if not B12(db_path):
return None
import sqlite3, duckdb
conn = sqlite3.connect(db_path) if db_path.endswith('.db') else duckdb.connect(db_path)
cur = conn.cursor()
cur.execute(query)
result = cur.fetchall()
conn.close()
with open(output_filename, 'w') as file:
file.write(str(result))
return result
# B6: Web Scraping
def B6(url, output_filename):
import requests
result = requests.get(url).text
with open(output_filename, 'w') as file:
file.write(str(result))
# B7: Image Processing
def B7(image_path, output_path, resize=None):
from PIL import Image
if not B12(image_path):
return None
if not B12(output_path):
return None
img = Image.open(image_path)
if resize:
img = img.resize(resize)
img.save(output_path)
# B8: Audio Transcription
# def B8(audio_path):
# import openai
# if not B12(audio_path):
# return None
# with open(audio_path, 'rb') as audio_file:
# return openai.Audio.transcribe("whisper-1", audio_file)
# B9: Markdown to HTML Conversion
def B9(md_path, output_path):
import markdown
if not B12(md_path):
return None
if not B12(output_path):
return None
with open(md_path, 'r') as file:
html = markdown.markdown(file.read())
with open(output_path, 'w') as file:
file.write(html)
# B10: API Endpoint for CSV Filtering
# from flask import Flask, request, jsonify
# app = Flask(__name__)
# @app.route('/filter_csv', methods=['POST'])
# def filter_csv():
# import pandas as pd
# data = request.json
# csv_path, filter_column, filter_value = data['csv_path'], data['filter_column'], data['filter_value']
# B12(csv_path)
# df = pd.read_csv(csv_path)
# filtered = df[df[filter_column] == filter_value]
# return jsonify(filtered.to_dict(orient='records'))