{"id":446165,"date":"2025-01-26T09:04:16","date_gmt":"2025-01-26T09:04:16","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=446165"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=446165","title":{"rendered":"<span>AI \u0432 \u044d\u043d\u0442\u0435\u0440\u043f\u0440\u0430\u0439\u0437\u0435<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041c\u043d\u0435\u043d\u0438\u0435.<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432 \u043a\u043e\u0440\u043f\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u043c IT \u044d\u0442\u043e, \u043a\u0430\u043a \u0438 \u043f\u0440\u0435\u0436\u0434\u0435: \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u0438 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p>AI \u0438, \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435, \u0410\u0433\u0435\u043d\u0442\u044b AI, \u0432 \u044d\u0442\u043e\u0439 \u0441\u0444\u0435\u0440\u0435, \u0432 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0435 2-3 \u0433\u043e\u0434\u0430, \u043c\u0430\u043b\u043e \u0447\u0442\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u044e\u0442.<\/p>\n<p>\u0412 \u043a\u043e\u0440\u043f\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u0435\u043a\u0442\u043e\u0440\u0435 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0438 \u0440\u0435\u0430\u043a\u0446\u0438\u043e\u043d\u043d\u043e\u0441\u0442\u0438, \u0447\u0442\u043e  \u0431\u0443\u0441\u0442 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0435\u0441\u0435\u0442 AI \u0441\u0442\u0430\u043d\u0435\u0442 \u043a\u0430\u043f\u043b\u0435\u0439 \u0432 \u043c\u043e\u0440\u0435.<\/p>\n<p>\u041c\u0438\u0433\u0440\u0430\u0446\u0438\u044f \u0441 Oracle \u043d\u0430 Postgresql \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0435\u0437\u0434 \u0441 Lotus Domino, \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u043a\u0440\u0443\u043f\u043d\u044b\u0445 \u043d\u0435-IT \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0439 \u043f\u0440\u0438\u043d\u0435\u0441\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e\u043b\u044c\u0437\u044b, \u0447\u0435\u043c \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 AI, \u0437\u0434\u0435\u0441\u044c \u0438 \u0441\u0435\u0439\u0447\u0430\u0441.<\/p>\n<p>\u0411\u0435\u0437 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438 \u0441\u0442\u0435\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 AI \u043d\u0435 \u043e\u0442\u043e\u0431\u044c\u0435\u0442 OPEX \u0438 \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 CAPEX.<\/p>\n<p>\u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0440\u0435\u0432\u043e\u043b\u044e\u0446\u0438\u043e\u043d\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u0443\u0436\u0435 \u0432 \u044d\u0442\u043e\u043c \u0433\u043e\u0434\u0443 \u2013 \u0437\u0430\u043f\u0430\u0434\u043d\u044b\u0435 \u043a\u043e\u0440\u043f\u043e\u0440\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0430\u0443\u0442\u043e\u0442\u0440\u0435\u043d\u0438\u043d\u0433, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 \u0418\u043d\u0434\u0438\u0438.<\/p>\n<p>\u0412\u043e\u0442 \u043a\u0441\u0442\u0430\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0435\u0431\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0430 \u043f\u043e\u0447\u0442\u0443 \u043f\u0440\u0438\u0441\u044b\u043b\u0430\u044e\u0442 \u043f\u0438\u0441\u044c\u043c\u0430 \u0441 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c\u0438 csv, json \u0438 xml \u0444\u0430\u0439\u043b\u0430\u043c\u0438. \u0421\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0438 \u0438\u0449\u0435\u0442 \u043f\u0438\u0441\u044c\u043c\u0430 \u0441 \u0441\u043b\u043e\u0432\u043e\u043c \u00abdocuments\u00bb \u0432 \u0442\u0435\u043c\u0435 \u0438 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c \u0444\u0430\u0439\u043b\u043e\u043c \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 csv. \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u044d\u0442\u0438 \u0444\u0430\u0439\u043b\u044b \u0432 \u043f\u0430\u043f\u043a\u0443.<\/p>\n<pre><code class=\"python\">import imaplib import email from email.header import decode_header import os import csv  IMAP_SERVER = \"imap.yandex.com\" EMAIL = \"email@yandex.com\" PASSWORD = \"password\" DOWNLOAD_FOLDER = \"attachments\"  if not os.path.exists(DOWNLOAD_FOLDER):     os.makedirs(DOWNLOAD_FOLDER)  def connect_to_imap():     try:         print(f\"Connecting to IMAP server: {IMAP_SERVER}\")         mail = imaplib.IMAP4_SSL(IMAP_SERVER, port=993)         mail.login(EMAIL, PASSWORD)         mail.select(\"INBOX\")         print(\"Connected successfully.\")         return mail     except imaplib.IMAP4.error as e:         print(f\"IMAP error: {e}\")         print(\"Check your email and password, or enable app passwords if 2FA is enabled.\")         return None     except Exception as e:         print(f\"Unexpected error: {e}\")         return None  def decode_header_value(encoded_value):     decoded_parts = decode_header(encoded_value)     result = \"\"     for part, encoding in decoded_parts:         if isinstance(part, bytes):             try:                 result += part.decode(encoding or \"utf-8\")             except LookupError:                 result += part.decode(\"latin-1\")             except UnicodeDecodeError:                 result += part.decode(\"utf-8\", errors=\"ignore\")         else:             result += part     return result  def extract_csv_attachments(msg):     for part in msg.walk():         if part.get_content_maintype() == \"multipart\":             continue         if part.get(\"Content-Disposition\") is None:             continue          filename = part.get_filename()         if filename and filename.lower().endswith(\".csv\"):             filename = decode_header_value(filename)             print(f\"Found CSV attachment: {filename}\")              filepath = os.path.join(DOWNLOAD_FOLDER, filename)             with open(filepath, \"wb\") as f:                 f.write(part.get_payload(decode=True))             print(f\"Saved CSV attachment: {filename}\")  def fetch_emails():     mail = connect_to_imap()     if not mail:         return      try:         status, messages = mail.search(None, 'SUBJECT \"documents\"')         if status != \"OK\":             print(\"No emails found with 'documents' in the subject.\")             return          email_ids = messages[0].split()         print(f\"Found {len(email_ids)} emails with 'documents' in the subject.\")          for mail_id in reversed(email_ids):             status, data = mail.fetch(mail_id, \"(RFC822)\")             if status != \"OK\":                 continue              msg = email.message_from_bytes(data[0][1])             subject = decode_header_value(msg[\"Subject\"])             print(f\"Processing email: {subject}\")              extract_csv_attachments(msg)     finally:         mail.logout()  if __name__ == \"__main__\":     fetch_emails() <\/code><\/pre>\n<p>\u0414\u0440\u0443\u0433\u043e\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u0437\u0430\u0431\u0438\u0440\u0430\u0435\u0442 csv \u0438 \u043f\u0435\u0440\u0435\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442 \u0438\u0445 \u0432 <a href=\"https:\/\/duckdb.org\" rel=\"noopener noreferrer nofollow\">duckDB<\/a> \u2013 \u0443\u043b\u044c\u0442\u0440\u0430\u0431\u044b\u0441\u0442\u0440\u0430\u044f \u043a\u043e\u043b\u043e\u043d\u043e\u0447\u043d\u0430\u044f RDBMS, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u0440\u0435\u0434\u0438 \u0434\u0430\u0442\u0430-\u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u043e\u0432:<\/p>\n<pre><code class=\"python\">import os import duckdb  DUCKDB_PATH = \"my_database.duckdb\"  ATTACHMENTS_DIR = \"attachments\"  def send_csv_to_duckdb():     conn = duckdb.connect(DUCKDB_PATH)     print(f\"Connected to DuckDB database: {DUCKDB_PATH}\")      for filename in os.listdir(ATTACHMENTS_DIR):         if filename.endswith(\".csv\"):             filepath = os.path.join(ATTACHMENTS_DIR, filename)             table_name = os.path.splitext(filename)[0]             print(f\"Processing file: {filename}\")              quoted_table_name = f'\"{table_name}\"'              conn.execute(                 f\"CREATE OR REPLACE TABLE {quoted_table_name} AS SELECT * FROM read_csv_auto('{filepath}')\"             )             print(f\"Data from {filename} sent to DuckDB table {quoted_table_name}.\")      print(\"All CSV files processed.\")  if __name__ == \"__main__\":     send_csv_to_duckdb() <\/code><\/pre>\n<p><a href=\"https:\/\/www.metabase.com\" rel=\"noopener noreferrer nofollow\">Metabase<\/a> \u2013 \u043e\u0434\u0438\u043d \u0438\u0437 \u043b\u0443\u0447\u0448\u0438\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code>docker run -d -p 3000:3000 -v \"$(pwd)\":\/srv --name metabase metabase\/metabase <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 duckdb, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u043b\u0430\u0433\u0438\u043d:<\/p>\n<pre><code>https:\/\/github.com\/MotherDuck-Open-Source\/metabase_duckdb_driver <\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0432 \u0434\u0435\u043b\u043e \u0432\u0441\u0442\u0443\u043f\u0430\u0435\u0442 <a href=\"https:\/\/slingdata.io\" rel=\"noopener noreferrer nofollow\">Sling<\/a> \u044d\u0442\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u043c\u0435\u0436\u0434\u0443 \u0431\u0430\u0437\u0430\u043c\u0438 \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449. \u0412\u043c\u0435\u0441\u0442\u043e \u043d\u0430\u0433\u0440\u043e\u043c\u043e\u0436\u0434\u0435\u043d\u0438\u044f UI \u0438 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0432\u0440\u043e\u0434\u0435 <a href=\"https:\/\/airbyte.com\" rel=\"noopener noreferrer nofollow\">Airbyte<\/a>, \u044d\u0442\u0438 \u0440\u0435\u0431\u044f\u0442\u0430 \u0440\u0435\u0448\u0438\u043b\u0438 \u043f\u043e\u0439\u0442\u0438 \u043f\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u043f\u0443\u0442\u0438 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 rsync \u0438\u043b\u0438 rclone \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<pre><code class=\"bash\">curl -LO 'https:\/\/github.com\/slingdata-io\/sling-cli\/releases\/latest\/download\/sling_linux_amd64.tar.gz' \\   &amp;&amp; tar xf sling_linux_amd64.tar.gz \\   &amp;&amp; rm -f sling_linux_amd64.tar.gz \\   &amp;&amp; chmod +x sling  mv sling \/usr\/local\/bin\/ <\/code><\/pre>\n<pre><code>$ sling conns list +--------------------------+-----------------+-------------------+ | CONN NAME                | CONN TYPE       | SOURCE            | +--------------------------+-----------------+-------------------+ | AWS_S3                   | FileSys - S3    | sling env yaml    | | DO_SPACES                | FileSys - S3    | sling env yaml    | | LOCALHOST_DEV            | DB - PostgreSQL | dbt profiles yaml | | MSSQL                    | DB - SQLServer  | sling env yaml    | | MYSQL                    | DB - MySQL      | sling env yaml    | | ORACLE_DB                | DB - Oracle     | env variable      | | MY_PG                    | DB - PostgreSQL | sling env yaml    | +--------------------------+-----------------+-------------------+ <\/code><\/pre>\n<p>\u0414\u0430\u0442\u0430 \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043f\u0440\u043e\u0441\u0442\u043e\u043c YAML \u0444\u0430\u0439\u043b\u0435. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0431\u0440\u0430\u0442\u044c csv \u0444\u0430\u0439\u043b \u0438 \u043f\u0435\u0440\u0435\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 PostgreSQL \u0438 minio s3 \u0434\u043b\u044f \u0434\u043e\u043b\u0433\u043e\u0441\u0440\u043e\u0447\u043d\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f:<\/p>\n<pre><code>version: 1 sources:   duckdb_source:     type: duckdb     path: \/path\/to\/your_database.duckdb  targets:   minio_target:     type: s3     bucket: &lt;bucket&gt;     access_key_id: &lt;access_key_id&gt;     secret_access_key: '&lt;secret_access_key&gt;'     endpoint: '&lt;endpoint&gt;'     url_style: path    postgres_target:     type: postgres     host: postgres_host     port: 5432     database: mydb     username: user     password: password  pipelines:   - name: duckdb_to_minio     source: duckdb_source     target: minio_target     query: \"SELECT * FROM sales\"     mode: overwrite    - name: duckdb_to_postgres     source: duckdb_source     target: postgres_target     query: \"SELECT * FROM sales\"     mode: overwrite <\/code><\/pre>\n<p>\u041d\u0443 \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 AI. \u041a\u0443\u0434\u0430 \u0436\u0435 \u0431\u0435\u0437 \u043d\u0435\u0433\u043e?<br \/> <a href=\"https:\/\/ollama.com\/\" rel=\"noopener noreferrer nofollow\">Ollama<\/a>\u00a0\u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 AI \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e CLI \u043d\u043e \u0438 \u043e\u0442\u043b\u0438\u0447\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043d\u0430 Python.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c\u043a\u0443:<\/p>\n<pre><code>pip install ollama graphvizollama run qwen2.5-coder:7b <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0441\u0432\u043e\u0435\u0439 \u0432\u0435\u0441\u043e\u0432\u043e\u0439 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 qwen2.5 \u044d\u0442\u043e \u043e\u0434\u043d\u0430 \u0438\u0437 \u043b\u0443\u0447\u0448\u0438\u0445 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 LLM.<\/p>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e qwen \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u0440\u0430\u0442\u043a\u043e\u0435 \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 csv \u043d\u0430 10 \u0433\u0438\u0433\u0430\u0431\u0430\u0439\u0442, \u0430 \u0435\u0441\u043b\u0438 \u043d\u0430\u0434\u043e \u043d\u0430\u0440\u0438\u0441\u0443\u0435\u0442 \u0433\u0440\u0430\u0444\u0438\u043a\u0438 \u0438 \u0441\u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u0432 \u043d\u0443\u0436\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442. <\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/\/post_images\/eca\/126\/eda\/eca126eda5b55d4c0d0d73297c494efe.png\" alt=\"analyze_csv.py\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/\/post_images\/eca\/126\/eda\/eca126eda5b55d4c0d0d73297c494efe.png\"\/><\/p>\n<div><figcaption>analyze_csv.py<\/figcaption><\/div>\n<\/figure>\n<p>\u0412\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a\u043e\u0439 \u0432\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435 \u043f\u0440\u043e\u043c\u043f\u0442: <\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/\/post_images\/6aa\/9a7\/9e7\/6aa9a79e710c959fea3912314b44103e.png\" alt=\"\u043f\u0440\u043e\u043c\u043f\u0442\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/\/post_images\/6aa\/9a7\/9e7\/6aa9a79e710c959fea3912314b44103e.png\"\/><\/p>\n<div><figcaption>\u043f\u0440\u043e\u043c\u043f\u0442<\/figcaption><\/div>\n<\/figure>\n<p> \u0421\u043a\u0440\u0438\u043f\u0442: <\/p>\n<pre><code class=\"python\">#!\/usr\/bin\/env python3 import csv import ollama import argparse import logging from typing import Optional  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')  PROMPT_TEMPLATE = \"\"\"[INST] &lt;&lt;SYS&gt;&gt; You are a data analysis expert. Analyze this CSV data and:  1. Summarize the data 2. Identify trends or patterns 3. Provide insights and recommendations  Format response with: - Markdown analysis - Key insights - Recommendations for further analysis &lt;&lt;\/SYS&gt;&gt;  CSV Data: {data} [\/INST]\"\"\"  def read_csv(file_path: str) -&gt; str:     try:         with open(file_path, \"r\") as file:             reader = csv.reader(file)             rows = [\",\".join(row) for row in reader]         return \"\\n\".join(rows)     except Exception as e:         logging.error(f\"Error reading CSV file: {e}\")         raise  def analyze_csv(csv_file: str, context_size: Optional[int] = None) -&gt; str:     try:         logging.info(f\"Reading CSV file: {csv_file}\")         csv_text = read_csv(csv_file)         logging.info(f\"Extracted CSV text: {csv_text[:100]}...\")          options = {}         if context_size:             options['max_tokens'] = context_size          logging.info(\"Sending data to Ollama model...\")         response = ollama.chat(             model='qwen2.5-coder:7b',             messages=[{'role': 'user', 'content': PROMPT_TEMPLATE.format(data=csv_text)}],             options=options         )['message']['content']         logging.info(\"Received response from Ollama model\")          return response      except Exception as e:         logging.error(f\"An error occurred: {e}\")         raise  if __name__ == \"__main__\":     parser = argparse.ArgumentParser(description='CSV AI Analyzer')     parser.add_argument('csv_file', help='Input CSV file')     parser.add_argument('--context-size', type=int, help='Optional context size (max tokens) for the Ollama model')     args = parser.parse_args()      try:         report = analyze_csv(args.csv_file, args.context_size)         print(\"\\nAnalysis Report:\")         print(report)     except Exception as e:         logging.error(f\"Script failed: {e}\") <\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/876638\/\"> https:\/\/habr.com\/ru\/articles\/876638\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041c\u043d\u0435\u043d\u0438\u0435.<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432 \u043a\u043e\u0440\u043f\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u043c IT \u044d\u0442\u043e, \u043a\u0430\u043a \u0438 \u043f\u0440\u0435\u0436\u0434\u0435: \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u0438 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p>AI \u0438, \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435, \u0410\u0433\u0435\u043d\u0442\u044b AI, \u0432 \u044d\u0442\u043e\u0439 \u0441\u0444\u0435\u0440\u0435, \u0432 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0435 2-3 \u0433\u043e\u0434\u0430, \u043c\u0430\u043b\u043e \u0447\u0442\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u044e\u0442.<\/p>\n<p>\u0412 \u043a\u043e\u0440\u043f\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u0435\u043a\u0442\u043e\u0440\u0435 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0438 \u0440\u0435\u0430\u043a\u0446\u0438\u043e\u043d\u043d\u043e\u0441\u0442\u0438, \u0447\u0442\u043e  \u0431\u0443\u0441\u0442 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0435\u0441\u0435\u0442 AI \u0441\u0442\u0430\u043d\u0435\u0442 \u043a\u0430\u043f\u043b\u0435\u0439 \u0432 \u043c\u043e\u0440\u0435.<\/p>\n<p>\u041c\u0438\u0433\u0440\u0430\u0446\u0438\u044f \u0441 Oracle \u043d\u0430 Postgresql \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0435\u0437\u0434 \u0441 Lotus Domino, \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u043a\u0440\u0443\u043f\u043d\u044b\u0445 \u043d\u0435-IT \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0439 \u043f\u0440\u0438\u043d\u0435\u0441\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e\u043b\u044c\u0437\u044b, \u0447\u0435\u043c \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 AI, \u0437\u0434\u0435\u0441\u044c \u0438 \u0441\u0435\u0439\u0447\u0430\u0441.<\/p>\n<p>\u0411\u0435\u0437 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438 \u0441\u0442\u0435\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 AI \u043d\u0435 \u043e\u0442\u043e\u0431\u044c\u0435\u0442 OPEX \u0438 \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 CAPEX.<\/p>\n<p>\u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0440\u0435\u0432\u043e\u043b\u044e\u0446\u0438\u043e\u043d\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u0443\u0436\u0435 \u0432 \u044d\u0442\u043e\u043c \u0433\u043e\u0434\u0443 \u2013 \u0437\u0430\u043f\u0430\u0434\u043d\u044b\u0435 \u043a\u043e\u0440\u043f\u043e\u0440\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0430\u0443\u0442\u043e\u0442\u0440\u0435\u043d\u0438\u043d\u0433, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 \u0418\u043d\u0434\u0438\u0438.<\/p>\n<p>\u0412\u043e\u0442 \u043a\u0441\u0442\u0430\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0435\u0431\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0430 \u043f\u043e\u0447\u0442\u0443 \u043f\u0440\u0438\u0441\u044b\u043b\u0430\u044e\u0442 \u043f\u0438\u0441\u044c\u043c\u0430 \u0441 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c\u0438 csv, json \u0438 xml \u0444\u0430\u0439\u043b\u0430\u043c\u0438. \u0421\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0438 \u0438\u0449\u0435\u0442 \u043f\u0438\u0441\u044c\u043c\u0430 \u0441 \u0441\u043b\u043e\u0432\u043e\u043c \u00abdocuments\u00bb \u0432 \u0442\u0435\u043c\u0435 \u0438 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c \u0444\u0430\u0439\u043b\u043e\u043c \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 csv. \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u044d\u0442\u0438 \u0444\u0430\u0439\u043b\u044b \u0432 \u043f\u0430\u043f\u043a\u0443.<\/p>\n<pre><code class=\"python\">import imaplib import email from email.header import decode_header import os import csv  IMAP_SERVER = \"imap.yandex.com\" EMAIL = \"email@yandex.com\" PASSWORD = \"password\" DOWNLOAD_FOLDER = \"attachments\"  if not os.path.exists(DOWNLOAD_FOLDER):     os.makedirs(DOWNLOAD_FOLDER)  def connect_to_imap():     try:         print(f\"Connecting to IMAP server: {IMAP_SERVER}\")         mail = imaplib.IMAP4_SSL(IMAP_SERVER, port=993)         mail.login(EMAIL, PASSWORD)         mail.select(\"INBOX\")         print(\"Connected successfully.\")         return mail     except imaplib.IMAP4.error as e:         print(f\"IMAP error: {e}\")         print(\"Check your email and password, or enable app passwords if 2FA is enabled.\")         return None     except Exception as e:         print(f\"Unexpected error: {e}\")         return None  def decode_header_value(encoded_value):     decoded_parts = decode_header(encoded_value)     result = \"\"     for part, encoding in decoded_parts:         if isinstance(part, bytes):             try:                 result += part.decode(encoding or \"utf-8\")             except LookupError:                 result += part.decode(\"latin-1\")             except UnicodeDecodeError:                 result += part.decode(\"utf-8\", errors=\"ignore\")         else:             result += part     return result  def extract_csv_attachments(msg):     for part in msg.walk():         if part.get_content_maintype() == \"multipart\":             continue         if part.get(\"Content-Disposition\") is None:             continue          filename = part.get_filename()         if filename and filename.lower().endswith(\".csv\"):             filename = decode_header_value(filename)             print(f\"Found CSV attachment: {filename}\")              filepath = os.path.join(DOWNLOAD_FOLDER, filename)             with open(filepath, \"wb\") as f:                 f.write(part.get_payload(decode=True))             print(f\"Saved CSV attachment: {filename}\")  def fetch_emails():     mail = connect_to_imap()     if not mail:         return      try:         status, messages = mail.search(None, 'SUBJECT \"documents\"')         if status != \"OK\":             print(\"No emails found with 'documents' in the subject.\")             return          email_ids = messages[0].split()         print(f\"Found {len(email_ids)} emails with 'documents' in the subject.\")          for mail_id in reversed(email_ids):             status, data = mail.fetch(mail_id, \"(RFC822)\")             if status != \"OK\":                 continue              msg = email.message_from_bytes(data[0][1])             subject = decode_header_value(msg[\"Subject\"])             print(f\"Processing email: {subject}\")              extract_csv_attachments(msg)     finally:         mail.logout()  if __name__ == \"__main__\":     fetch_emails() <\/code><\/pre>\n<p>\u0414\u0440\u0443\u0433\u043e\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u0437\u0430\u0431\u0438\u0440\u0430\u0435\u0442 csv \u0438 \u043f\u0435\u0440\u0435\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442 \u0438\u0445 \u0432 <a href=\"https:\/\/duckdb.org\" rel=\"noopener noreferrer nofollow\">duckDB<\/a> \u2013 \u0443\u043b\u044c\u0442\u0440\u0430\u0431\u044b\u0441\u0442\u0440\u0430\u044f \u043a\u043e\u043b\u043e\u043d\u043e\u0447\u043d\u0430\u044f RDBMS, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u0440\u0435\u0434\u0438 \u0434\u0430\u0442\u0430-\u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u043e\u0432:<\/p>\n<pre><code class=\"python\">import os import duckdb  DUCKDB_PATH = \"my_database.duckdb\"  ATTACHMENTS_DIR = \"attachments\"  def send_csv_to_duckdb():     conn = duckdb.connect(DUCKDB_PATH)     print(f\"Connected to DuckDB database: {DUCKDB_PATH}\")      for filename in os.listdir(ATTACHMENTS_DIR):         if filename.endswith(\".csv\"):             filepath = os.path.join(ATTACHMENTS_DIR, filename)             table_name = os.path.splitext(filename)[0]             print(f\"Processing file: {filename}\")              quoted_table_name = f'\"{table_name}\"'              conn.execute(                 f\"CREATE OR REPLACE TABLE {quoted_table_name} AS SELECT * FROM read_csv_auto('{filepath}')\"             )             print(f\"Data from {filename} sent to DuckDB table {quoted_table_name}.\")      print(\"All CSV files processed.\")  if __name__ == \"__main__\":     send_csv_to_duckdb() <\/code><\/pre>\n<p><a href=\"https:\/\/www.metabase.com\" rel=\"noopener noreferrer nofollow\">Metabase<\/a> \u2013 \u043e\u0434\u0438\u043d \u0438\u0437 \u043b\u0443\u0447\u0448\u0438\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code>docker run -d -p 3000:3000 -v \"$(pwd)\":\/srv --name metabase metabase\/metabase <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 duckdb, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u043b\u0430\u0433\u0438\u043d:<\/p>\n<pre><code>https:\/\/github.com\/MotherDuck-Open-Source\/metabase_duckdb_driver <\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0432 \u0434\u0435\u043b\u043e \u0432\u0441\u0442\u0443\u043f\u0430\u0435\u0442 <a href=\"https:\/\/slingdata.io\" rel=\"noopener noreferrer nofollow\">Sling<\/a> \u044d\u0442\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u043c\u0435\u0436\u0434\u0443 \u0431\u0430\u0437\u0430\u043c\u0438 \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449. \u0412\u043c\u0435\u0441\u0442\u043e \u043d\u0430\u0433\u0440\u043e\u043c\u043e\u0436\u0434\u0435\u043d\u0438\u044f UI \u0438 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0432\u0440\u043e\u0434\u0435 <a href=\"https:\/\/airbyte.com\" rel=\"noopener noreferrer nofollow\">Airbyte<\/a>, \u044d\u0442\u0438 \u0440\u0435\u0431\u044f\u0442\u0430 \u0440\u0435\u0448\u0438\u043b\u0438 \u043f\u043e\u0439\u0442\u0438 \u043f\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u043f\u0443\u0442\u0438 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 rsync \u0438\u043b\u0438 rclone \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<pre><code class=\"bash\">curl -LO 'https:\/\/github.com\/slingdata-io\/sling-cli\/releases\/latest\/download\/sling_linux_amd64.tar.gz' \\   &amp;&amp; tar xf sling_linux_amd64.tar.gz \\   &amp;&amp; rm -f sling_linux_amd64.tar.gz \\   &amp;&amp; chmod +x sling  mv sling \/usr\/local\/bin\/ <\/code><\/pre>\n<pre><code>$ sling conns list +--------------------------+-----------------+-------------------+ | CONN NAME                | CONN TYPE       | SOURCE            | +--------------------------+-----------------+-------------------+ | AWS_S3                   | FileSys - S3    | sling env yaml    | | DO_SPACES                | FileSys - S3    | sling env yaml    | | LOCALHOST_DEV            | DB - PostgreSQL | dbt profiles yaml | | MSSQL                    | DB - SQLServer  | sling env yaml    | | MYSQL                    | DB - MySQL      | sling env yaml    | | ORACLE_DB                | DB - Oracle     | env variable      | | MY_PG                    | DB - PostgreSQL | sling env yaml    | +--------------------------+-----------------+-------------------+ <\/code><\/pre>\n<p>\u0414\u0430\u0442\u0430 \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043f\u0440\u043e\u0441\u0442\u043e\u043c YAML \u0444\u0430\u0439\u043b\u0435. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0431\u0440\u0430\u0442\u044c csv \u0444\u0430\u0439\u043b \u0438 \u043f\u0435\u0440\u0435\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 PostgreSQL \u0438 minio s3 \u0434\u043b\u044f \u0434\u043e\u043b\u0433\u043e\u0441\u0440\u043e\u0447\u043d\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f:<\/p>\n<pre><code>version: 1 sources:   duckdb_source:     type: duckdb     path: \/path\/to\/your_database.duckdb  targets:   minio_target:     type: s3     bucket: &lt;bucket&gt;     access_key_id: &lt;access_key_id&gt;     secret_access_key: '&lt;secret_access_key&gt;'     endpoint: '&lt;endpoint&gt;'     url_style: path    postgres_target:     type: postgres     host: postgres_host     port: 5432     database: mydb     username: user     password: password  pipelines:   - name: duckdb_to_minio     source: duckdb_source     target: minio_target     query: \"SELECT * FROM sales\"     mode: overwrite    - name: duckdb_to_postgres     source: duckdb_source     target: postgres_target     query: \"SELECT * FROM sales\"     mode: overwrite <\/code><\/pre>\n<p>\u041d\u0443 \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 AI. \u041a\u0443\u0434\u0430 \u0436\u0435 \u0431\u0435\u0437 \u043d\u0435\u0433\u043e?<br \/> <a href=\"https:\/\/ollama.com\/\" rel=\"noopener noreferrer nofollow\">Ollama<\/a>\u00a0\u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 AI \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e CLI \u043d\u043e \u0438 \u043e\u0442\u043b\u0438\u0447\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043d\u0430 Python.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c\u043a\u0443:<\/p>\n<pre><code>pip install ollama graphvizollama run qwen2.5-coder:7b <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0441\u0432\u043e\u0435\u0439 \u0432\u0435\u0441\u043e\u0432\u043e\u0439 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 qwen2.5 \u044d\u0442\u043e \u043e\u0434\u043d\u0430 \u0438\u0437 \u043b\u0443\u0447\u0448\u0438\u0445 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 LLM.<\/p>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e qwen \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u0440\u0430\u0442\u043a\u043e\u0435 \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 csv \u043d\u0430 10 \u0433\u0438\u0433\u0430\u0431\u0430\u0439\u0442, \u0430 \u0435\u0441\u043b\u0438 \u043d\u0430\u0434\u043e \u043d\u0430\u0440\u0438\u0441\u0443\u0435\u0442 \u0433\u0440\u0430\u0444\u0438\u043a\u0438 \u0438 \u0441\u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u0432 \u043d\u0443\u0436\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442. <\/p>\n<figure class=\"\">\n<div><figcaption>analyze_csv.py<\/figcaption><\/div>\n<\/figure>\n<p>\u0412\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a\u043e\u0439 \u0432\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435 \u043f\u0440\u043e\u043c\u043f\u0442: <\/p>\n<figure class=\"\">\n<div><figcaption>\u043f\u0440\u043e\u043c\u043f\u0442<\/figcaption><\/div>\n<\/figure>\n<p> \u0421\u043a\u0440\u0438\u043f\u0442: <\/p>\n<pre><code class=\"python\">#!\/usr\/bin\/env python3 import csv import ollama import argparse import logging from typing import Optional  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')  PROMPT_TEMPLATE = \"\"\"[INST] &lt;&lt;SYS&gt;&gt; You are a data analysis expert. Analyze this CSV data and:  1. Summarize the data 2. Identify trends or patterns 3. Provide insights and recommendations  Format response with: - Markdown analysis - Key insights - Recommendations for further analysis &lt;&lt;\/SYS&gt;&gt;  CSV Data: {data} [\/INST]\"\"\"  def read_csv(file_path: str) -&gt; str:     try:         with open(file_path, \"r\") as file:             reader = csv.reader(file)             rows = [\",\".join(row) for row in reader]         return \"\\n\".join(rows)     except Exception as e:         logging.error(f\"Error reading CSV file: {e}\")         raise  def analyze_csv(csv_file: str, context_size: Optional[int] = None) -&gt; str:     try:         logging.info(f\"Reading CSV file: {csv_file}\")         csv_text = read_csv(csv_file)         logging.info(f\"Extracted CSV text: {csv_text[:100]}...\")          options = {}         if context_size:             options['max_tokens'] = context_size          logging.info(\"Sending data to Ollama model...\")         response = ollama.chat(             model='qwen2.5-coder:7b',             messages=[{'role': 'user', 'content': PROMPT_TEMPLATE.format(data=csv_text)}],             options=options         )['message']['content']         logging.info(\"Received response from Ollama model\")          return response      except Exception as e:         logging.error(f\"An error occurred: {e}\")         raise  if __name__ == \"__main__\":     parser = argparse.ArgumentParser(description='CSV AI Analyzer')     parser.add_argument('csv_file', help='Input CSV file')     parser.add_argument('--context-size', type=int, help='Optional context size (max tokens) for the Ollama model')     args = parser.parse_args()      try:         report = analyze_csv(args.csv_file, args.context_size)         print(\"\\nAnalysis Report:\")         print(report)     except Exception as e:         logging.error(f\"Script failed: {e}\") <\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/876638\/\"><\/a><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-446165","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/446165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=446165"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/446165\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=446165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=446165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=446165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}